• Hi,

    My website is https://www.straightforwardlegal.com 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: https://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: https://www.straightforwardlegal.com"); exit;

    However, 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

Viewing 6 replies - 1 through 6 (of 6 total)
  • You could use wp_redirect().

    So this:
    ("location: https://www.straightforwardlegal.com"); exit;

    Becomes this:
    wp_redirect("https://www.straightforwardlegal.com"); exit;

    But, that last message you echo will not get displayed; since the page will be sent to a redirect. You may have to pass a $_GET variable, and then check it from your home page, to display a message.

    Thread Starter mrmccarrin

    (@mrmccarrin)

    Thank you for your reply, however, it did not work and I get the same result?

    Does the email get sent?

    Thread Starter mrmccarrin

    (@mrmccarrin)

    Yes, the email gets sent without a problem and then it keeps the user on the page with the “Thank you for contacting us …..” message and it looks awful. I want to redirect the user to a new url after submitting the contact form.

    Well… it’s not the way I would do things… but it is definitely working if the email is being sent.

    Is this part of your theme/ a plugin? Did you create a custom template for your contact form?

    Perhaps something else is interfering and not allowing the redirect to take place.

    How exactly did you create this contact form?

    Thread Starter mrmccarrin

    (@mrmccarrin)

    This is not a plugin. It is a custom template. Unfortunately, I am not the one who created it. It was someone that my company has lost contact with. It was not working at all a few days ago, but I did get it to work.

    I would be willing to recreate from scratch if you do not think this is a good way to set up a contact form, but I honestly know nothing about PHP – do you have a suggestion about where to get started? Everything I google gets very confusing?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Redirecting My URL after submitting my contact form’ is closed to new replies.