stublackett Posted February 5, 2009 Share Posted February 5, 2009 Hi, I've got a 2 part purchase system setup. First part is you fill in your details, Second part pulls the POST values and confirms the purchase back for Worldpay. Thats all well and good, BUT there are Terms & Conditions for the particular purchase so I need on page 1 of the form the user to say "I accept the terms & Conditions" Once they accept the t's and c's it takes them to page 2 which confirms the order. How on earth do I check that the "I accept terms and conditions box" is ticked and once it is, Take them to page 2? and obviously how do I work it to say "Please accept the terms & conditions" if the box isnt ticked? My HTML Code if needed is <fieldset> <p>Please read our <a href="http://www.blairdrummond.com/events/terms.php" title="Terms & Conditions">Terms & Conditions </a>before purchasing</p> <li> <label>I Accept The Terms & Conditions</label> <input name="accept" type="checkbox" value="check" /> </li> </fieldset> Quote Link to comment https://forums.phpfreaks.com/topic/143914-solved-help-with-form-validation/ Share on other sites More sharing options...
JonnoTheDev Posted February 5, 2009 Share Posted February 5, 2009 You need the form to submit to the processing page (or have it submit to the same page and put the php validation at the top): if(strlen($_POST['accept'])) { // checkbox has been ticked - redirect to page 2 header("Location:page2.php"); exit(); } else { print "Please accept our terms and conditions"; } Something along those lines Quote Link to comment https://forums.phpfreaks.com/topic/143914-solved-help-with-form-validation/#findComment-755163 Share on other sites More sharing options...
JonnoTheDev Posted February 5, 2009 Share Posted February 5, 2009 You may also need to save the POST values into a session so you can recover them on the 2nd form i.e. session_start(); // validation part // if all fields are correctly filled in foreach($_POST as $key => $val) { $_SESSION[$key] = $val; } // redirect to page 2 Then on the 2nd page you can recover the values session_start(); // prints the name entered on page 1 print $_SESSION['name']; Quote Link to comment https://forums.phpfreaks.com/topic/143914-solved-help-with-form-validation/#findComment-755164 Share on other sites More sharing options...
stublackett Posted February 5, 2009 Author Share Posted February 5, 2009 You may also need to save the POST values into a session so you can recover them on the 2nd form i.e. session_start(); // validation part // if all fields are correctly filled in foreach($_POST as $key => $val) { $_SESSION[$key] = $val; } // redirect to page 2 Then on the 2nd page you can recover the values session_start(); // prints the name entered on page 1 print $_SESSION['name']; That seems a little tricky ? In my coding I've put it at the top of the page, Due to the header error you get after HTML So how do I set this out? At the moment it is : <?php if (isset($_POST['submitted'])) { // Start isset() IF if(strlen($_POST['accept'])) { // checkbox has been ticked - redirect to page 2 header("Location:order.php"); exit(); }else{ $error = "Please accept our terms and conditions"; } } // End of isset() ?> How would I associate this with your session code? Another spanner in the works as it were is, I have a ReCaptcha Anti Spam Script at the bottom of each page, How could I check that in the session ??? Quote Link to comment https://forums.phpfreaks.com/topic/143914-solved-help-with-form-validation/#findComment-755169 Share on other sites More sharing options...
JonnoTheDev Posted February 5, 2009 Share Posted February 5, 2009 // dont use isset() - bad function <?php // make sure you have this at the top of every page using sessions session_start(); if(strlen($_POST['submitted'])) { if(strlen($_POST['accept'])) { // store all post values into session array foreach($_POST as $key => $val) { $_SESSION[$key] = $val; } // checkbox has been ticked - redirect to page 2 header("Location:order.php"); exit(); } else{ // you can print this error somewhere on the page $error = "Please accept our terms and conditions"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/143914-solved-help-with-form-validation/#findComment-755174 Share on other sites More sharing options...
stublackett Posted February 5, 2009 Author Share Posted February 5, 2009 Excellent! Thanks Neil I just used extract($_SESSION) on the next page. Works a treat. Any ideas on how I can get this re-captcha check to function? Maybes on the 1st page of the form. As it doesnt like it on the second page, Unfortunatley Code for that is : Page 1 <?php require_once('recaptchalib.php'); $publickey = " "; // you got this from the signup page echo recaptcha_get_html($publickey); ?> Page 2 <?php require_once('recaptchalib.php'); $privatekey = "6LcUqAIAAAAAAAazqwngzEl7IoVb78orliVPKF3w"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { die ("<b>Anti Spam</b> <br />Please enter the Two Words located at the bottom of the Keeper for a day Order Form correctly. Click the back button to try again" . ""); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/143914-solved-help-with-form-validation/#findComment-755178 Share on other sites More sharing options...
JonnoTheDev Posted February 5, 2009 Share Posted February 5, 2009 Never used it. Youll have to use the docs Quote Link to comment https://forums.phpfreaks.com/topic/143914-solved-help-with-form-validation/#findComment-755179 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.