RE: PHP Form and Arrays help
| From: | Tim Ward | Date: | Wed, 25 Sep 2002 07:52:52 +0000 |
| Subject: | RE: PHP Form and Arrays help | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-117529@lists.php.net to get a copy of this message | ||
use a hidden input in front of each checkbox with the same name and
the value '0' (as opposed to '1' for the checkbox).
Tim
www.chessish.com
> -----Original Message-----
> From: Tom Ray [mailto:tom@blazestudios.com]
> Sent: 24 September 2002 17:24
> To: php-general@lists.php.net
> Subject: PHP Form and Arrays help
>
>
> I'm having a small problem with a form I'm designing and I
> hope someone can
> point me in the right direction here. The form's function is
> rather simple
> actaully. It's supposed to take the information, run through
> it to make sure
> all the required fields have data in them, if there is a
> blank required field
> it is supposed to redraw the form showing the field missed
> but also store the
> data that was already submitted so you don't have to fill the
> form out all over
> again. Now I have it so it stores the values of text boxes,
> drop down menus and
> radio buttons but I'm having a real tough time with the check
> box values.
> Example of what I'm doing: (Gender Selection with Radio Buttons).
>
> I declare an array in my PHP by doing
> $genderarray=array();
>
> Then I store the value of the form for the redraw like so:
> $mygender=$HTTP_POST_VARS[gender];
> $genderarray[$mygender]="checked";
>
> In the actaul form I decalre a global:
> global genderarray();
>
> And under the gender selection I have:
> <input name=gender type=radio value="Male" <?=
> $genderarray["Male"] ?>" >
> (works the same for the Female)
>
>
> Now my question is how can I do this with check boxes. I
> thought I could
> through them all into a single array, then pull out the ones
> who have values to
> them, but that's not working the way I thought.
>
> Any thoughts or suggestions?
>
>