Dealing with Multiple Selections
Since PHP stores all form fields and their values as indices in the
$_POST
array, it can't deal with multiple fields being sent
with exactly the same name.
PHP therefore uses a special array notation to represent mutiple
selections:
<form method=post action="showFields.cgi">
<select name="Options[]" size=5 multiple>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
<option>Option 4</option>
<option>Option 5</option>
</select>
<input type=submit name=GO value=GO>
</form>
|
$_POST = Array
(
[Options] => Array
(
[0] => Option 2
[1] => Option 3
)
[GO] => GO
)
|
This approach can also be used for other form fields as well. In addition,
index values can be used rather than automatically generating a new,
numerically indexed element.
<form method=post action="showFields.cgi">
<input name="f1[Fred]" value="fred">
<input name="f1[John]" value="john">
<input name="f1[Alias for John]" value="sam"><br />
<input type=checkbox name="f2[]" value="0 0">
<input type=checkbox name="f2[]" value="0 1">
<input type=checkbox name="f2[]" value="0 2"><br />
<input type=checkbox name="f2[]" value="1 0">
<input type=checkbox name="f2[]" value="1 1">
<input type=checkbox name="f2[]" value="1 2">
<input type=submit name=GO value="DO IT">
</form>
|
$_POST = Array
(
[f1] => Array
(
[Fred] => fred
[John] => john
[Alias for John] => sam
)
[GO] => DO IT
)
|
Multiple-dimensional arrays are also possible using this notation:
<form method=post action="showFields.cgi">
<input type=checkbox name="f1[0][0]" value="set">
<input type=checkbox name="f1[0][1]" value="set">
<input type=checkbox name="f1[0][2]" value="set"><br />
<input type=checkbox name="f1[1][0]" value="set">
<input type=checkbox name="f1[1][1]" value="set">
<input type=checkbox name="f1[1][2]" value="set">
<input type=submit name=GO value="DO IT">
</form>
|
$_POST = Array
(
[f1] => Array
(
[0] => Array
(
[1] => set
)
[1] => Array
(
[2] => set
)
)
[GO] => DO IT
)
This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
0 comments:
Post a Comment