Megan Posted August 5, 2014 Share Posted August 5, 2014 Hi, i have a contact form with this code: <?php if(isset($_POST['submit'])) { $flag=1; if($_POST['yourname']=='') { $flag=0; echo "Please Enter Your Name<br>"; } else if(!preg_match('/[a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*/',$_POST['yourname'])) { $flag=0; echo "Please Enter Valid Name<br>"; } if($_POST['email']=='') { $flag=0; echo "Please Enter E-mail<br>"; } else if(!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $_POST['email'])) { $flag=0; echo "Please Enter Valid E-Mail<br>"; } if($_POST['subject']=='') { $flag=0; echo "Please Enter Subject<br>"; } if($_POST['message']=='') { $flag=0; echo "Please Enter Message"; } if ( empty($_POST) ) { print 'Sorry, your nonce did not verify.'; exit; } else { if($flag==1) { wp_mail(get_option("admin_email"),trim($_POST[yourname])." sent you a message from StraightForwardLegal.com".get_option("blogname"),stripslashes(trim($_POST['message'])),"From: ".trim($_POST['yourname'])." <".trim($_POST['email']).">\r\nReply-To:".trim($_POST['email'])); echo "Thank you for contacting us!<br> We have received your email. <br> One of our Workers' Compensation Attorneys <br> will be in touch with you as soon as possible"; header ("location: http://www.straightforwardlegal.com"); exit; } } } ?> and then, <div class="frontForm"> <form method="post" id="contactus_form"><span style="font-size: 12px;> <div class="left"> Name*:<br><input type="text" name="yourname" id="yourname" rows="1" maxlength="35"><br> Email*:<br><input type="text" name="email" id="email" rows="1" value=""><br> Phone*:<br><input type="text" name="subject" id="subject" rows="1" columns="8" style= "max-height: 18px; min-height: 18px;" value="" /></td></tr> </div> <div class="right" style="margin-top: -120px;"/> Message*:<textarea name="message" id="message" rows="5" style="height: 90px;"></textarea><br><br> <input type="submit" name="submit" id="submit" value="Send"/></span> </form> </div> </div> </div> </div> I used header ("location: http://www.straightforwardlegal.com"); exit; but, it does not work. After submitting my contact form, the user gets taken to my contact page instead of going to my home page? I was wondering if someone could let me know what I have done wrong? Thank you, Megan Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 5, 2014 Share Posted August 5, 2014 And where is the line that is sending you there? And what is the name of the code you are showing us? Quote Link to comment Share on other sites More sharing options...
Megan Posted August 5, 2014 Author Share Posted August 5, 2014 I am not sure what is sending me there? I do not know why it is going to where it is going? Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted August 5, 2014 Share Posted August 5, 2014 Have you tried adding some debugging statements to see where the script is ending? For example: <?php //... if($flag==1) { echo '<div>here (flag==1)</div>'; wp_mail(get_option("admin_email"),trim($_POST[yourname])." sent you a message from StraightForwardLegal.com".get_option("blogname"),stripslashes(trim($_POST['message'])),"From: ".trim($_POST['yourname'])." <".trim($_POST['email']).">\r\nReply-To:".trim($_POST['email'])); echo "Thank you for contacting us!<br> We have received your email. <br> One of our Workers' Compensation Attorneys <br> will be in touch with you as soon as possible"; //header ("location: http://www.straightforwardlegal.com"); exit; } echo '<div>here (flag!=1)</div>'; //... ?> Also, do you have PHP set to show all errors and warnings? If not, enabling them may provide a clue. You can enable all errors and warnings by adding the following to your script: <?php //REPORT ALL PHP ERRORS error_reporting(E_ALL); ini_set('display_errors', 1); ?> Of course, you'll want to remove the above code once everything is fixed. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 5, 2014 Share Posted August 5, 2014 I wanted to know the name of the script you showed us in case IT was the script that was what you were seeing unexpectedly. (Since your form tag didn't tell me.) Quote Link to comment 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.