Passing Array values to a validation script a

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
skicrud
Forum Newbie
Posts: 1
Joined: Wed Oct 01, 2008 2:29 pm

Passing Array values to a validation script a

Post by skicrud »

~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


I need to create a dynamic table and do so w/the following code

Code: Select all

$facility_sql=mysql_query("SELECT * from facility");
while($myrow=mysql_fetch_array($facility_sql))
{
$myrow[Fac_Name]<br><input type=checkbox name=Facility[] value=$myrow[Fac_ID]<br>";
}
 
This works great to create the checkboxes. From here I need to pass the array to a validation page where I use the code

Code: Select all

$Facility=$_POST['Facility'];
if(!isset($Facility) or count($Facility)==0){
$status_form="NOTOK";
$msg .="At least one facility needs to be checked<br>";
}
This also works
If the validation script returns true I enter the values from the Facility array with

Code: Select all

foreach(_POST['Facility'] as $value){
$sql="INSERT into where_used_facility(Fac_ID,Prod_ID)VALUSE($value,$Last_Prod_ID)";
$result=mysql_query($sql)
}
this code works


My problem is how do I set the checkbox to checked when the validation scripr returns an error on another field. I do not want to have the user reenter values for previously checked checkboxes.I have tried Implode/Explode and serialize/unserialize alune with urlencode all with no luck


~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
koen.h
Forum Contributor
Posts: 268
Joined: Sat May 03, 2008 8:43 am

Re: [color=#BF0000]Passing Array values to a validation script a

Post by koen.h »

I hope you filter the results you enter into your database.

To answer your question: what you can do in your form is examining the $_POST array and if the checkbox was checked echo 'checked="checked"'.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Passing Array values to a validation script a

Post by papa »

You should look through your HTML code for the checkbox though.

Code: Select all

$facility_sql=mysql_query("SELECT * from facility");
while($myrow=mysql_fetch_array($facility_sql))
{
$myrow[Fac_Name]<br><input type=checkbox name=Facility[] value=$myrow[Fac_ID]<br>";
}
Post Reply