Re: Variables in forms

From: Date: Mon, 23 Jun 2008 06:40:49 +0000
Subject: Re: Variables in forms
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-275793@lists.php.net to get a copy of this message
Ron Piggott wrote:
I am writing a form right now. I would like to make the checkbox an array variable. The first part of the array is the component reference, the second part is the package reference. What name would you assign to it that I could use in processing the form in the PHP script this posts to? Ron <tr> <td valign="top"><font face="times new roman"><center>Children's Activities</center></td> <td valign="top"><font face="times new roman"><center>Child's ABC's</center></td> <td><center><input type="checkbox" name="component_1_package_1"></center></td> <td><center><input type="checkbox" name="component_1_package_2"></center></td> </tr>
In your form, do this <input type="checkbox" name="components[1][1]"> <input type="checkbox" name="components[1][2]"> Then in PHP do this. This is if the form was sent via POST <?php $components = your_cleaning_function($_POST['components']); foreach ( $components AS $component_id => $packages ) {
    foreach ( $packages AS $package_id => $value ) {
        // At this point, the only way you would get here is if
        // a person was to place a check mark in the check box
        // So, one would assume that this component/package
        // combo was infact checked.
    }
} ?>

« previous php.general (#275793) next »