Results 1 to 6 of 6

Thread: Form with Required Checkbox

  1. #1
    Join Date
    Oct 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Form with Required Checkbox

    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

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    <?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

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    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 Code:
    <?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.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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

  5. #5
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    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.

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •