How can I add a checkbox that's required to be checked, before this form info is submitted, with text saying You Must Agree To The Terms & Conditions, or this form can't be submitted unless the box is checked? And a link from the words Terms & Conditions. thanks.... This is the page I want to add it to the bottom of: <?php global $account; ?> <script language="javascript" type="text/javascript"> function populate(frm){ frm.email.value = frm.user_name.value } </script> <form method="POST" action="index.php"> <TABLE align='center' width="440" valign='top' cellpadding="0" cellspacing="1" style='border:1px solid gray' style="padding: 5px;" > <tr><td> </td></tr> <input class='field' type='hidden' name='command' value='account'> <input class='field' type='hidden' name='param' value='signup'> <tr><td colspan='2' class='pageTitle'><div class='hLine'><font face="Arial" color="#000000" size="3">Create New Account</font></div></td></tr> <tr><td> </td></tr> <tr> <td class='fieldLabel' width="30%"><font face="Arial" color="#6B6B6B" size="2">Membership Type</font></td> <td align="center">[account_type_panel]</td></tr> <tr><td> </td></tr> <tr> <td class='fieldLabel' width="30%"><font face="Arial" color="#6B6B6B" size="2"> User Name</font></td> <td><input class='field' type='text' size='30' onBlur="populate(this.form);" maxlength="30" name='user_name' value='<?=$account->user_name ?>'> <span class='requiredField'> * </span><span class='errorMessage'><?=$account->get_error('user_name') ?></span></td> </tr> <tr> <td class='fieldLabel'><font face="Arial" color="#6B6B6B" size="2"> Password</font></td> <td><input class='field' type='password' size='30' maxlength="30" name='password' value='<?=$account->password ?>'> <span class='requiredField'> * </span><span class='errorMessage'><?=$account->get_error('password') ?></span></td> </tr> <tr> <td class='fieldLabel'><font face="Arial" color="#6B6B6B" size="2"> Re-Enter Password</font></td> <td><input class='field' type='password' size='30' maxlength="30" name='reenter_password' value='<?=$account->reenter_password ?>'> <span class='requiredField'> * </span><span class='errorMessage'><?=$account->get_error('reenter_password') ?></span></td> </tr> <tr> <td class='fieldLabel'><font face="Arial" color="#6B6B6B" size="2"> First Name</font> </td> <td ><input class='field' type='text' size='40' maxlength="50" name='first_name' value='<?=$account->first_name ?>'> <span class='requiredField'> * </span><span class='errorMessage'><?=$account->get_error('first_name') ?></span></td> </tr> <tr> <td class='fieldLabel'><font face="Arial" color="#6B6B6B" size="2"> Last Name</font></td> <td><input class='field' type='text' size='40' maxlength="50" name='last_name' value='<?=$account->last_name ?>'> <span class='requiredField'> * </span><span class='errorMessage'><?=$account->get_error('last_name') ?></span></td> </tr> <tr><td></td></tr><tr><td class='fieldLabel'><font face="Arial" color="#6B6B6B" size="2"> Email Address</font></td> <td><input class='field' type='text' size='40' maxlength="50" name='email' value='<?=$account->email ?>'> <span class='requiredField'> * </span><span class='errorMessage'><?=$account->get_error('email') ?></span></td> </tr> <tr> <td class='fieldLabel'><font face="Arial" color="#6B6B6B" size="2"> Address</font></td> <td><input class='field' type='text' size='40' maxlength="70" name='address' value='<?=$account->address ?>'> <span class='requiredField'> * </span><span class='errorMessage'><?=$account->get_error('address') ?></span></td> </tr> <tr> <td class='fieldLabel'><font face="Arial" color="#6B6B6B" size="2"> Address 2</font></td> <td><input class='field' type='text' size='40' maxlength="70" name='address_second' value='<?=$account->address_second ?>'></td> </tr> <tr> <td class='fieldLabel'><font face="Arial" color="#6B6B6B" size="2"> City</font></td> <td><input class='field' type='text' size='40' maxlength="50" name='city' value='<?=$account->city ?>'> <span class='requiredField'> * </span><span class='errorMessage'><?=$account->get_error('city') ?></span></td> </tr> <tr> <td class='fieldLabel'><font face="Arial" color="#6B6B6B" size="2"> State/Province</font></td> <td><input class='field' type='text' size='35' maxlength="35" name='phone' value='<?=$account->phone ?>'> * </td> </tr> <tr> <td class='fieldLabel'><font face="Arial" color="#6B6B6B" size="2"> Zip/Postal Code</font></td> <td><input class='field' type='text' size='35' maxlength="35" name='zip_postal_code' value='<?=$account->zip_code ?>'> <span class='requiredField'> * </span><span class='errorMessage'><?=$account->get_error('zip_code') ?></span></td> </tr> <tr> <td class='fieldLabel'><font face="Arial" color="#6B6B6B" size="2"> Country</font></td> <td><input class='field' type='text' size='35' maxlength="35" name='mobile_phone_number' value='<?=$account->mobile_phone_number ?>'> * </td></tr> <tr><td> </td></tr><tr><td colspan="2" class='hLine' align="right"><span class='requiredField'> *</span><font face="Arial" color="#000000" size="2"> Required Field</font></td></tr> <tr><td colspan='2' align="right"><input class='button' type='submit' value='create'></td></tr><tr><td colspan="2"> </td></tr> </table> </form> Code (markup):
I use this script to validate whether user has checked the checkbox under Terms and Conditions. <script language="JavaScript" type="text/javascript"> function validator(){ var obj = document.formname; if (obj.agreement.checked != true) { alert("You must read and accept Terms and Conditions"); obj.agreement.focus(); return false; } return true; } </script> Code (markup): You need to substitute the formname in var obj = document.formname with the name of your form. This is a source for the form: <form name="formname" method="POST" onsubmit="return validator();" action="submit.php"> Code (markup): This is a source for checkbox: <input type="checkbox" name="agreement" value="yes" /> I have read and I accept Terms and Conditions Code (markup): Good luck!
Hello, here is a good example, how to valid a checkbox with javascript. http://www.elated.com/articles/form-validation-with-javascript/
Note however, this assumes the user has javascript enabled. Rather obvious, I know, but seeing as you posted in the PHP forum, you'll still need something server side, else those without javascript will be able to submit without clicking your box and hence legally won't have agreed to your T&Cs.
Good solution! Would you also need some code on the serverside though, to check the result of the variable, as some people may have Javascript disabled, and so the validation on the user's side wouldn't work? Edit: or, yeah, what he ^ said
Is there any way to accomplish my request without a javascript, so any user can the user must agree before Submitting?
No, because that would mean it's done client side and the user *always* has the option of turning any form of client side scripting off. But all you have to do is test the value when they do submit and if it isn't checked, send them back to the form (though do make sure you pre-populate it the second time with everything they typed first time!) It's really not difficult to do (off top of my head)... <?php $valid = false; if ($_POST['termsAndConditions']==1){ $valid=true; } if (!$valid){ echo '<form action="address of this page"........ method=..............>'; echo '<input type="text" name="something" value=$_POST["something"]>'; echo 'Agree Terms and Conditions<input type="checkbox" name="termsAndConditions">'; }else{ // We're all good to go, redirect to the next page... header("302............. }