graeme_1988 Posted March 30, 2011 Share Posted March 30, 2011 Hi, I rarely deal with PHP, so this may sound very easy, but I am struggling to figure out what to do. Basically I have created a website for a client that allows for customers to pay for certain packages using Paypal. They select the package they want, which then takes them to a data input page (email, tel no, name etc). Once they click submit, that information gets emailed to my client, and the customer is presented with the relevant Paypal page. What I need is on each data input page, for a checkbox to be available, so if the customer checks the checkbox, they get taken to a different paypal page rather than if they leave it blank. So really, what I need is if the checkbox is left blank and that page is submitted, the customer goes to Page A. If the checkbox is checked and they click submit, the customer goes to Page B. Any help would be greatly appreciated! Cheers Graeme Quote Link to comment https://forums.phpfreaks.com/topic/232163-php-beginners-help/ Share on other sites More sharing options...
cyberRobot Posted March 30, 2011 Share Posted March 30, 2011 You could send everyone to Page A. Then if the checkbox was clicked redirect them to Page B using header(). http://php.net/manual/en/function.header.php You could also look into using JavaScript. You should be able to modify where the form goes on the fly with JavaScript when someone clicks the checkbox. Off hand, I don't know what that code would be. If you decide to use a JavaScript solution, I would still recommend utilizing the PHP solution mentioned above as a backup. That way if JavaScript is turned off or doesn't work, the PHP solution would still redirect visitors. Quote Link to comment https://forums.phpfreaks.com/topic/232163-php-beginners-help/#findComment-1194275 Share on other sites More sharing options...
graeme_1988 Posted March 30, 2011 Author Share Posted March 30, 2011 Thanks for that - managed to get it working! Quote Link to comment https://forums.phpfreaks.com/topic/232163-php-beginners-help/#findComment-1194388 Share on other sites More sharing options...
graeme_1988 Posted April 4, 2011 Author Share Posted April 4, 2011 I managed to get it to work, so that the value of the checkbox determines the page the user will come to. However, now the email doesn't get sent. I'm assuming it is because I am declaring variables twice, or perhaps it is because the message send part of the code is repeated, but I've tried a few different ways and it still doesn't work. I have pasted my code below (I imagine some of the more experienced PHP experts out there will have a fit when they see how poor/messy it is!). Any help would be much appreciated! <?php $YourEmail = "emailaddress@hotmail.co.uk"; $WebsiteURL = " ####.html"; $subject = "Subject"; if (empty ($_POST['agree'])) { if(!isset($_POST['email'])) { header("location: $WebsiteURL"); exit(); } $_POST['name'] = preg_replace("/[\n\r]+/", "", $_POST['name']); $_POST['email'] = preg_replace("/[\n\r]+/", "", $_POST['email']); ## THE EMAIL TEXT $text = " ----------------------------------------------------------------------------- Title Text ----------------------------------------------------------------------------- Name: ".$_POST['name']." \n\n Email: ".$_POST['email']." \n\n Past Experience: ".$_POST['exp']." \n\n Area: ".$_POST['area']." \n\n Contact Number: ".$_POST['phone']." \n\n Referral: ".$_POST['referral']." \n\n "; $subject = stripslashes($subject); $text = stripslashes($text); @mail("$YourEmail", $subject, $text, "From: <$subject>"); After header("Location: ####.html"); exit; } else { if(!isset($_POST['email'])) { header("location: $WebsiteURL"); exit(); } $_POST['name'] = preg_replace("/[\n\r]+/", "", $_POST['name']); $_POST['email'] = preg_replace("/[\n\r]+/", "", $_POST['email']); ## THE EMAIL TEXT $text = " ----------------------------------------------------------------------------- Title text ----------------------------------------------------------------------------- Name: ".$_POST['name']." \n\n Email: ".$_POST['email']." \n\n Past Experience: ".$_POST['exp']." \n\n Area: ".$_POST['area']." \n\n Contact Number: ".$_POST['phone']." \n\n Referral: ".$_POST['referral']." \n\n "; $subject = stripslashes($subject); $text = stripslashes($text); @mail("$YourEmail", $subject, $text, "From: <$subject>"); After header("Location: ####.html"); exit; } ?> Just to reiterate - the user will enter their details on a form, then click submit. The data then gets emailed to the client. If they check the checkbox, they will then get sent to "page a", if they leave it blank, then they get sent to "page b". Cheers! Graeme Quote Link to comment https://forums.phpfreaks.com/topic/232163-php-beginners-help/#findComment-1196605 Share on other sites More sharing options...
dcro2 Posted April 4, 2011 Share Posted April 4, 2011 What is "After" in your code? I'm guessing it's not in your actual code right? Also, you're setting the From: header to $subject instead of a valid email. Quote Link to comment https://forums.phpfreaks.com/topic/232163-php-beginners-help/#findComment-1196628 Share on other sites More sharing options...
graeme_1988 Posted April 4, 2011 Author Share Posted April 4, 2011 Yeah the 'after' part was something I had commented in - I tried to remove all comments when I pasted it on here, so sorry about that! The 'from subject' part worked fine before - it just meant that when someone sends the form, and the client receives the email, it says it is from 'Website User Capture Page etc'. Quote Link to comment https://forums.phpfreaks.com/topic/232163-php-beginners-help/#findComment-1196642 Share on other sites More sharing options...
ignace Posted April 4, 2011 Share Posted April 4, 2011 Php is good and easy to learn. I just learnt it when I started my freelancing jobs. 2 posts and both contain a link to your website, trying to boost your low PageRank website through this high-volume forum? Quote Link to comment https://forums.phpfreaks.com/topic/232163-php-beginners-help/#findComment-1196780 Share on other sites More sharing options...
graeme_1988 Posted April 5, 2011 Author Share Posted April 5, 2011 Php is good and easy to learn. I just learnt it when I started my freelancing jobs. 2 posts and both contain a link to your website, trying to boost your low PageRank website through this high-volume forum? Haha there's always one that tries it Quote Link to comment https://forums.phpfreaks.com/topic/232163-php-beginners-help/#findComment-1197087 Share on other sites More sharing options...
graeme_1988 Posted April 8, 2011 Author Share Posted April 8, 2011 I don't suppose anyone has spotted where I have been going wrong? Feel bad for keep asking but it's pushing my sanity to the limit haha Quote Link to comment https://forums.phpfreaks.com/topic/232163-php-beginners-help/#findComment-1198614 Share on other sites More sharing options...
cyberRobot Posted April 8, 2011 Share Posted April 8, 2011 Do you know which part of the code is getting executed? One way to find out is to display something on the screen in the various if statements. Note that you'll want to comment out the redirects so that you see the messages. For example, you could do something like this: <?php ... if (empty ($_POST['agree'])) { print 'here - agree'; ... } else { print 'here - agree blank'; ... } ... ?> You could also look into removing the @ before the mail() functions. The @ surpresses errors which might provide a clue as to why the e-mail isn't being sent. You might want to consider adding an if around the mail() functions so that the redirect doesn't happen if the e-mail isn't sent. <?php ... if(mail("$YourEmail", $subject, $text, "From: <$subject>")) { header("Location: ####.html"); exit; } else { //<-- display error about there being a problem sending the e-mail and/or log error } ... ?> Quote Link to comment https://forums.phpfreaks.com/topic/232163-php-beginners-help/#findComment-1198711 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.