Hello, I’m converting a site I created many years ago from Classic ASP to PHP and learning PHP at the same time. I’m finding PHP is more “nuts and bolts” level than ASP - for example I’ve written my own Request_Cookies and Response_Cookies functions to do the string handling to replace the ASP Request.Cookies and Response.Cookies - needed because I use cookies with keys. These make it easy to convert the site code and work well but I’m struggling to do the same with forms, specifically with checkboxes.
The code I’m trying to borrow is the first user contributed note in the PHP $_POST manual page regarding using arrays for multiple values of the same input field - PHP: $_POST - Manual
The bones of my form which uses the POST method are:-
<tr>
<td>
<input type="checkbox" id="cht1" name="ttype" value="T1"
<?php if ((Request_Cookies("T1","selected")=="true")) { ?>CHECKED<?php } ?> >
<a href="javascript:toggleCheck('cht1')" class="noLink"> T1 </a>
</td>
</tr>
<tr>
<td>
<input type="checkbox" id="cht2" name="ttype" value="T2"
<?php if ((Request_Cookies("T2","selected")=="true")) { ?>CHECKED<?php } ?> >
<a href="javascript:toggleCheck('cht2')" class="noLink"> T2 </a>
</td>
</tr>
…repeated for T3 to T18
This posts something (I’m not sure what the raw data looks like as I’ve never had to think about it) which I can process in ASP with
For Each ttype in Request.Form("ttype")
Response.Cookies(ttype,"selected","true");
$i=$i+1;
Next
So only the ttypes that are checked appear in the posted data and I can match them to cookies of the same name with no manipulation needed.
Now in PHP I think I need to have ttype as an array but replacing name=“ttype” with name=“ttype[0]” , name=“ttype[1]” etc. for the 18 ttypes just causes the form not to submit. No error message, it just sits there and does nothing.
My target page just contains print_r($_POST); at the moment so I can see what I’m getting when the form does submit.
I haven’t managed to locate any useful information so please can anyone point me in the right direction?
Thanks in advance.