Re: Variables in forms
| From: | Ron Piggott | Date: | Mon, 23 Jun 2008 10:24:51 +0000 |
| Subject: | Re: Variables in forms | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-275800@lists.php.net to get a copy of this message | ||
Jim what you sent is very helpful.
I had an error message when I submitted the form with a POST
your_cleaning_function
gave me this error:
Fatal error: Call to undefined function: your_cleaning_function()
I am trying to save the ones that were checked to a mySQL table and then
notify the user the database was updated. The first thing that happens
is the code you gave me below. How do I resolve this error? I get the
concept of functions, but this isn't an area of PHP that I have used
before.
Ron
On Sun, 2008-06-22 at 23:40 -0700, Jim Lucas wrote:
> 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.
> }
> }
>
> ?>
>