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
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
<?php
if ($_POST['fieldname'] != "checked") {
die('error');
}
?>
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
Originally posted by: JMH
Can some please help me with the code to make this checkbox required before it posts the information?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.Originally posted by: djr33
PHP Code:<?php
if ($_POST['fieldname'] != "checked") {
die('error');
}
?>
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.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
If this is the case what are the method that we have in our hands to reduce server load?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
Yes i understood lack of security in Client-side scripts.
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?
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
Bookmarks