dynamic fom checkbox validation error message

I have had this issue now for weeks and I am at the end of my tether! I am ready to throw the towel in and give up computers for good!!
Rant over….
I am building a website for a friend (and learning php as I go!) who wants to gather user information for registration purposes via php forms. I have everything else working except this one small component, all linked up to a database and no issues except checking if the user checked the ‘terms and conditions’ checkbox or not! To build the picture up I am not using any java script just a pure css php form.
Firstly I build my form from an aray of all the named fields and I have a 2 if statements
Array (“name” => “Name”,
“surname” => “Surname”,
“email” => “Email”,
“password” => “Password”,
“hear” => “Hear about”,
“termsconditions” => “Terms&conditions”,
If hear is selected it creates a drop down of all the options, and if it is termsconditions it creates a checkbox, all the other fields are text boxes.
On first submission the error handling looks for blank fields and captures the empty fields in an aray, reloads the form with an error message at the top informing the user which fields are blank - This works.
After the blanks are sorted I have a validation section which checks each field to ensure it matches the allowed characters - This works. If any of the above fail the good data is inserted into an array and the form is reloaded with it in.

Now the error handling I can’t figure out is the checkbox, I have the database set up to accept a Boolean ‘1’ but I don’t set the value of the checkbox as one as I am led to believe that if it is checked by the user it passes one via the termsconditions variable? Is this correct? This code creates my form checkbox
//new code for termsconditions check box
else if($field == “termsconditions”)
echo "

I agree to the terms&conditions

This is the code below I have to catch the variable not being set in the error handling, but it does not do anything, if I leave the checkbox unchecked the data is inserted into the database but no message appears to tell you that you have not checked the database and no boolean goes into the field.

      if (!preg_match("/^[1]$/",$value)) 
         $errors[] = "$value has not been selected "; 

Any help much appreciated as I can’t seem to find any help on the web, most info is static forms with the variables passesd individually.



Sponsor our Newsletter | Privacy Policy | Terms of Service