Output array data from GET
I'd like to know if there's a way that one can output data from a form sent by a page. The data is sent in array form, and the form looks like this:
<form method="post" action="/?module=scoreboard&n=index">
<table width="101" border="0" align="center">
<tr>
<th colspan="2" scope="col"><p>Select Division(s)</p>
<p> </p></th>
</tr>
<tr>
<td width="74"> <label for="div1">Division 1</label></td>
<td width="20"><input type="checkbox" name="div[]" id="div1" value="1" />
</td>
</tr>
<tr>
<td><label for="div2">Division 2</label></td>
<td><input type="checkbox" name="div[]" id="div2" value="2"/>
</td>
</tr>
<tr>
<td><label for="div3">Division 3</label></td>
<td><input type="checkbox" name="div[]" id="div3" value="3" />
</td>
</tr>
<tr>
<td开发者_如何学C><label for="div4">Division 4</label></td>
<td><input type="checkbox" name="div[]" id="div4" value="4" />
</td>
</tr>
<tr>
<td colspan="2"><p>
</p>
<p>
<input type="submit" name="submit" id="submit" value="Display Standings" />
</p></td>
</tr>
</table>
</form>
I need to output the data from this form, in hidden fields so the page can be refreshed at certain periods of time.
Any ideas?
Thanks in advance!
As you're using an array HTML-side, you simply need to use the corresponding PHP array in your POST data.
For example, to see if the 1st div[]
checkbox was checked, you'd need to see if the corresponding value is in the $_POST['div'] array. For example:
if(in_array(1, $_POST['div']) {
// The first checkbox was selected. Do exciting things here.
}
To check the second, use in_array(2, $_POST['div'])
and so on.
print_r($_POST);
to see the complete structure of the sent data.
精彩评论