Perhaps someone has already come up with a solution for this, however, I've written a very nice function that goes through any form and checks all required fields. However, if I use input type="Radio" or input type="Checkbox", the each() does not pick up on these form fields. Is there a better way way of doing this?
I've tried the following two ways:
while(list($key, $val) = each($_POST)) {
array_push($formKeys, $key);
array_push($formVals, $val);
}
or:
$formKeys = array_keys($_POST);
$formVals = array_values($_POST);
both ways ignore the radio and checkbox fields, what am I missing? I haven't tried to use multiple select boxes, though selects work just fine.
each(_POST)
Moderator: General Moderators
-
mdunnOutlaw
- Forum Newbie
- Posts: 3
- Joined: Sat Sep 07, 2002 11:03 pm
- Location: Spokane, WA
- Contact:
-
mdunnOutlaw
- Forum Newbie
- Posts: 3
- Joined: Sat Sep 07, 2002 11:03 pm
- Location: Spokane, WA
- Contact:
Answer to my own question :)
If a checkbox or radio button is not selected in the form then it does not come through. The each(_POST) works fine as long as a value is selected, however, if it is not then you have to do a specific check for that field. If it does not exists in the _POST array of keys then you know that nothing was selected and if it is a required field then you can send them back. 
Have you set the "name" property with check-box form?
Code: Select all
<input type="checkbox" name="SOMETHING">-
mdunnOutlaw
- Forum Newbie
- Posts: 3
- Joined: Sat Sep 07, 2002 11:03 pm
- Location: Spokane, WA
- Contact:
RE: each(_POST)
Yes I did set the name. The radio elements look as follows:
What I found was that since neither is selected/checked and they remain so when the form is submitted then they do not come across in the list of keys for the each(_POST). It's not a PHP issue it's just how IE and probably Netscape (haven't tried it with Netscape), handles those particular form elements when nothing is selected. I've run into the same issues with other languages; I'm really not sure why it didn't occur to me to begin with. Thanks for the input though
.
Code: Select all
<input type="Radio" name="pro" value="Yes">
<input type="Radio" name="pro" value="No">