Re: Checkbox related...
| From: | Ernest E Vogelsinger | Date: | Sun, 16 Feb 2003 19:14:31 +0000 |
| Subject: | Re: Checkbox related... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-135768@lists.php.net to get a copy of this message | ||
At 19:57 16.02.2003, Dhaval Desai said:
--------------------[snip]--------------------
>I have a form with 5 checkboxes. I want to make sure that a user checks
>atleast 2 boxes before he can proceed. How can that be made possible.
--------------------[snip]--------------------
You have 2 options:
1) Client-side JavaScript: in the forms OnSubmit handler, loop your
checkboxes and make sure at least 2 are checked. If the precondition is not
met, return false from the onSubmit handler.
2) Server-Side via PHP: make an array of all available checkboxes, and walk
this array to see if you have at least 2 of these checkboxes set in your
$_REQUEST array. If the precondition is not met, retransmit the original
form without proceeding.
I'd prefer a combination of both - the JS method saves the user an
unnecessary form transmission, speeding up his entry. The server-side
script method makes sure there's no malicious user trying to trick the
system *g*
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/