Page 1 of 1

Check Boxes PHP

Posted: Thu May 01, 2003 12:00 pm
by pete105
Well i ahve 12 check boxes

I want it so when user clicks one it goes to the database
but when user clicks no check boxes i want an error to appear


i started this code can anyone please provide me with an example
i ahve been trying to fiqure this out forever

Code:
$checkboxes = array("C49", "C49");


foreach ($checkboxes as $box) {
if (isset($_POST[$box])) {
$found = false;
break;
}

echo 'You have not entered all the required details.<br />'
.'Please go back and try again.';
exit;
}

try javascript

Posted: Thu May 01, 2003 12:50 pm
by phpScott
It would probalby be easier to check if they have selected a box using javascript.

If you want to go to the database everytime they check a box you will have to put a onClick eventhandler on each check box to submit the form.

phpScott

Posted: Thu May 01, 2003 12:59 pm
by nincha
for validation, u should just use a simple javascript for onsubmit that shows a promt box when no box was checked. However, if u want to use php, than just use this:

Code: Select all

if( ($_POST&#1111;'checkbox1_name']=="") && ($_POST&#1111;'checkbox2_name']="") ) //so on
&#123;echo 'You have not entered all the required details.<br />' 
.'Please go back and try again.'; &#125;
This method can become messy once reaching above 3 boxes, but you can always try looping or somthing else. Hope this helps.

Posted: Fri May 02, 2003 2:37 am
by twigletmac
Of course a JavaScript only solution is useless if a user has JS turned off (or it's not available to them), you should still use a server-side solution as backup.

Mac