Log in

View Full Version : Form with Required Checkbox



JMH
10-04-2006, 08:50 PM
Hello,

I am trying to make a form with a required checkbox (similar to the one when you register here).

Can some please help me with the code to make this checkbox required before it posts the information?

Thanks,
JMH

djr33
10-05-2006, 12:03 AM
<?php
if ($_POST['fieldname'] != "checked") {
die('error');
}
?>

codeexploiter
10-05-2006, 04:16 AM
Originally posted by: JMH

Can some please help me with the code to make this checkbox required before it posts the information?




Originally posted by: djr33

<?php
if ($_POST['fieldname'] != "checked") {
die('error');
}
?>

I think this kind of validation can be done using Javascript at the client-side itself rather than using server-side PHP code. There is not much advantage using Server-side code for the purpose here.

djr33
10-05-2006, 04:28 AM
Well, before "posting" can mean different things.
If this is a forum, before posting is after submission and pre-adding to the database.
If not, "post" isn't the right verb... sending is what happens when you submit a form.

As for using php vs. client side, client side is nice. It'll allow you to give live feedback to the user and not send the form. However, it is NOT secure, and if you need security or to be sure the form WAS validated, you MUST use php.

codeexploiter
10-05-2006, 04:41 AM
Originally posted by: djr33
As for using php vs. client side, client side is nice. It'll allow you to give live feedback to the user and not send the form. However, it is NOT secure, and if you need security or to be sure the form WAS validated, you MUST use php


If this is the case what are the method that we have in our hands to reduce server load?

Yes i understood lack of security in Client-side scripts.

djr33
10-05-2006, 10:41 AM
Uh. Server load?
The difference between the server load from using an if statement for a checkbox and serving even a simple image to a visitor, for example, is immense.
I have no clue what you mean.
If statements don't overload the server.

Really, why have an agreement if they don't actually need to agree?