PHP Login System with Admin Features

This forum was created to talk about the PHP Login System with admin features created by jpmaster77 on evolt's website

    I agree to the terms & conditions" Checkbox help

    Share

    ragtech

    Number of posts: 10
    Age: 54
    Registration date: 2009-04-08

    I agree to the terms & conditions" Checkbox help

    Post  ragtech on Mon Apr 27, 2009 12:33 am

    I have been trying all day and I just can't get a simple checkbox to work. It's driving me crazy because I have had so much success modifying this script to fit my needs and this seems like it would be so simple... but not for me and not today!


    All I want is on the register.php is a check box that says "I agree to the terms and conditions" If the box is checked they proceed as normal (I don't want to save the agree to terms in a database or anything like that)...

    But if the checkbox is not checked I want them to return to the form and echo "You Must agree to terms and conditions to proceed"

    That's it, That's all I need but I'll be dammed if I can get this to work.

    Seems like it all should be very simple... I would post what I've tried but I have tried so many things and discarded them afterwards.. I just wouldn't know what to post here that would be of any help at all.

    can anybody help me?

    Thanks
    -rg

    Linchpin311

    Number of posts: 220
    Age: 29
    Localisation: Long Island
    Registration date: 2007-05-14

    Re: I agree to the terms & conditions" Checkbox help

    Post  Linchpin311 on Mon Apr 27, 2009 4:55 pm

    honestly, i usually do these types of things with a javascript alert box, its a lot simpler and much less of a headache (the top hit from a google search for "Javascript Checkbox Validation").

    but if you are looking to keep it all php...
    first off let me say, i am assuming you have added fields in the past to register.php mainly based on your quote, "I have had so much success modifying this script to fit my needs" so i am skipping a couple of obvious steps. If you need me to go back and explain everything step by step let me know.

    ok so, in register.php all you really need to do is put in a checkbox input. make sure you name it and give it a value so you can access it later in session.php. consider the following:
    Code:
    <input type="checkbox" name="accept_terms" value="1"> I have read and accept the terms or whatever, dude.<br>
    <?php echo $form->error("accept_terms"); ?>

    now the real magic happens in session.php. when we you are making all the checks in the register() function (like to make sure the user has entered a valid email address), somewhere in there you need to put a check to make sure $accept_terms has a value of 1 and nothing else. maybe something like:
    Code:
    /* Accept Terms error checking */
    $field = "accept_terms"; 
    if($accept_terms != 1){
       $form->setError($field, "* You must accept the terms to register");
    }

    thats really all you need to make this work. of course make sure you are editing the appropriate lines in process.php or else $accept_terms will never make it to session.php. hope this helps you out!


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.

    ragtech

    Number of posts: 10
    Age: 54
    Registration date: 2009-04-08

    Re: I agree to the terms & conditions" Checkbox help

    Post  ragtech on Mon Apr 27, 2009 5:50 pm

    You know I had tried that exactly as you wrote it and I kept getting the result (value="1" was always the same)

    Then I read your comment:

    "of course make sure you are editing the appropriate lines in process.php or else $accept_terms will never make it to session.php. hope this helps you out!"

    ... and "duh" that's when I realized I was not passing the value to session.php

    Once I added the appropriate $_POST['accept_terms'] to the process.php it worked like a charm.

    Thanks a bunch!
    -rg

    Linchpin311

    Number of posts: 220
    Age: 29
    Localisation: Long Island
    Registration date: 2007-05-14

    Re: I agree to the terms & conditions" Checkbox help

    Post  Linchpin311 on Mon Apr 27, 2009 10:07 pm

    lol no worries. ive done it a dozen times. glad it works! Very Happy


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.

      Current date/time is Sat Nov 01, 2014 1:11 am