Skip to main content

Form validation? 1212 Responses

Last post: 1 month, 1 week ago | Thread started: Feb 8, 10, 1:15 p.m.

RespondNew TopicDisable Images

  • boobs

    I am having such a hard time getting my head around this. I've looked around on the internets, and I just can't seem to understand how to do this. How do I set it up so that if a checkbox on a form is not checked, the form can't be submitted?

    Feb 8, 10, 1:15 p.m. – Permalink
  • boobs

    They have to check the checkbox for the form to be submitted.

    next note >add note

    You must be logged in to add a note. Login now or register for an account.

    Cancel
    Dog-earFeb 8, 10, 1:18 p.m. – Permalink
  • fugged

    http://gist.github.com/298594

    next note >add note

    You must be logged in to add a note. Login now or register for an account.

    Cancel
    Dog-earFeb 8, 10, 1:22 p.m. – Permalink
  • boobs

    That doesn't help at all!

    No squeeze for you!

    next note >add note

    You must be logged in to add a note. Login now or register for an account.

    Cancel
    Dog-earFeb 8, 10, 1:24 p.m. – Permalink
  • fugged

    not sure whatcha need then?

    • Well, don't have the crucial part "psuedo code."boobs
    + add note

    You must be logged in to add a note. Login now or register for an account.

    Cancel
    Dog-earFeb 8, 10, 1:26 p.m. – Permalink
  • fugged

    submit handler function should return false to prevent the form from submitting.

    so in your handler function you need to test and see if the checkbox is checked. if so, return true - (and the for will submit) otherwise return false (and the form will be prevented from submitting)

    next note >add note

    You must be logged in to add a note. Login now or register for an account.

    Cancel
    Dog-earFeb 8, 10, 1:27 p.m. – Permalink
  • ETM

    So I'll assume you mean in javascript since you didn;t say.

    if (frm.insertboxname.checked == false) {
    alert ('** Error message **');
    return false;
    }

    next note >add note

    You must be logged in to add a note. Login now or register for an account.

    Cancel
    Dog-earFeb 8, 10, 1:28 p.m. – Permalink
  • bzsaw

    http://www.willmaster.com/librar…

    next note >add note

    You must be logged in to add a note. Login now or register for an account.

    Cancel
    Dog-earFeb 8, 10, 1:28 p.m. – Permalink
  • fugged

    I gotcha boobs. check it again.:
    http://gist.github.com/298594

    next note >add note

    You must be logged in to add a note. Login now or register for an account.

    Cancel
    Dog-earFeb 8, 10, 1:42 p.m. – Permalink
  • boobs

    Well, fugged, I put that into my page, and it doesn't seem to work. Even if the box is not checked, the form still submits, and the information goes into the database.

    • I'm guessing you neglected the part where the js is explicitly referencing the checkbox by idacescence1/2
      No, I put the ID into the js. Where it says "foo." Right?boobs2/2
    next note >+ add note

    You must be logged in to add a note. Login now or register for an account.

    Cancel
    Dog-earFeb 8, 10, 2:04 p.m. – Permalink
  • fugged

    make sure you don't have any other javascript errors going on. if you have a url, I can help you debug what's going on.

    next note >add note

    You must be logged in to add a note. Login now or register for an account.

    Cancel
    Dog-earFeb 8, 10, 2:08 p.m. – Permalink
  • ayport

    Can always do it server side:

    HTML:
    <form action="formProcessor.php" method="post">
    <input type="checkbox" value="yes" name="checkbox">
    <input type="submit">
    </form>

    PHP (asp or asp.net works the same):
    <?
    if ($_POST['checkbox'] == "yes")
    {
    // process rest of form
    }
    else
    {
    echo "please check the box";
    }
    ?>

    next note >add note

    You must be logged in to add a note. Login now or register for an account.

    Cancel
    Dog-earFeb 8, 10, 2:15 p.m. – Permalink
  • boobs

    fugged got me through it! Big squeeze for fugged!

    next note >add note

    You must be logged in to add a note. Login now or register for an account.

    Cancel
    Dog-earFeb 8, 10, 2:42 p.m. – Permalink

Login or Register to respond to this

Skip to main content