Re: Variables in forms

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Quoting Ron Piggott <ron.php@xxxxxxxxxxxxxxxxxx>:


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.
     }
}

?>




The function "your_cleaning_function" is no native PHP function.
Jim just added it to show that you need to filter input data.

To test the script just remove the function call completely. But remember when you put this in production. You want some sort of input filtering.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux