1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Require check in box

Discussion in 'PHP' started by ECS Dave, Sep 22, 2010.

  1. #1
    How do I make a form submit button active only if a single option box is checked (or ticked), preferably onpage, and in php?

    Thanks, and...
    SEMrush
    Be Well!
    ECS Dave
     
    ECS Dave, Sep 22, 2010 IP
    SEMrush
  2. lowridertj

    lowridertj Well-Known Member

    Messages:
    2,882
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    195
    #2
    here is an example for you
    found on sitepoint

    
    
    <SCRIPT LANGUAGE="JavaScript">
    function verifForm(formulaire)
      {
      if(formulaire.tick.checked == false)
        alert('Please check the box');
      else
     
        formulaire.submit();
     
    }
    </SCRIPT>
     
    <body>
     
    <FORM>
    <input name="tick" type="checkbox">
    <INPUT name="Submit" TYPE="submit" onClick="verifForm(this.form)" VALUE="submit" >
    </FORM>
     
    </body>
    </html>
    
    
    HTML:
     
    lowridertj, Sep 22, 2010 IP
  3. ECS Dave

    ECS Dave Active Member

    Messages:
    244
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Thanks, but I don't seem to be able to get your code to work.

    I placed the script section first into the head section of my webpage,
    added the code to my form, then tested it... No luck.
    Then tried it with the script in the body section, still no luck.

    Thanks for trying though! :)

    Be Well!
    ECS Dave

    P.S. php won't do this?!?!?
     
    ECS Dave, Sep 22, 2010 IP
  4. lowridertj

    lowridertj Well-Known Member

    Messages:
    2,882
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    195
    #4
    what is your form in your web page?

    I will try to put it together here for you
     
    lowridertj, Sep 22, 2010 IP
  5. ECS Dave

    ECS Dave Active Member

    Messages:
    244
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #5
    Thanks Man!

    Here's the form code:
    <form action="index.php" method="post">
    User entered form fields are here
    <input name="signup" type="submit" value="Sign Me Up!">
    <input type="hidden" name="action" value="affsignup">
    </form>
    Code (markup):
    and the box I want required to be checked is:
    <input name="Iagree" type="checkbox">
    Code (markup):
    Be Well!
    ECS Dave
     
    ECS Dave, Sep 22, 2010 IP
  6. lowridertj

    lowridertj Well-Known Member

    Messages:
    2,882
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    195
    #6
    
    
    <?php
    
    if(isset($_POST['Iagree'])){
    	$Iagree = $_POST['Iagree'];
    }
    
    if($Iagree != 'checked'){
    	//show error 
    else{
    	//proceed with processing
    }
    
    //Note below I added a value to the check box
    
    /*/
    //  Also I only have this using print to show the admin notes better and via php.  you can end the php before the html with ?> and start it back up after the html with <?php
    /*/
    print '
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <form action="index.php" method="post">
    <p>User entered form fields are here</p>
    <p><input name="signup" type="submit" value="Sign Me Up!"></p>
    <p><input type="hidden" name="action" value="affsignup"></p>
    <p><input name="Iagree" type="checkbox" value="checked"> You must check this box</p>
    </form>
    </body>
    </html>';
    
    ?>
    
    PHP:
     
    lowridertj, Sep 23, 2010 IP
    ECS Dave likes this.
  7. ECS Dave

    ECS Dave Active Member

    Messages:
    244
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #7
    I really appreciate what you've done! Really!

    Prior to getting the instant email notification of your post, I had asked in another forum, and they had suggested a solution to my quandary. I tried it, and it worked (albeit with some "messing about", on my part, with the referenced code)!

    You can see the resultant page at http://trustedsalesstore.com/shop/jv.php where, unless the checkbox is checked (or ticked, as some say), the submit button cannot be pressed... :cool:

    Thanks again for your efforts, and a big REP to you for them!!!

    Be Well!
    ECS Dave
     
    ECS Dave, Sep 23, 2010 IP