Grow your CSS skills. Land your dream job.

PHP form redirect

  • # December 5, 2009 at 7:14 pm

    I am using Chris’s simple form on a wordpress site for one of my clients. Normally in the contactengine.php file I just put a file like index.html for the redirect. For the wordpress site I cannot do that. I have tried putting in the directory (ie, /contact/) as well as the full url, but after a form is submitted wordpress pulls up a 404 Not Found page.

    Here is the contactengine.php code:

    Code:
    < ?php

    $EmailFrom = "site@trading-strategy.com";
    $EmailTo = "jdtrader21@yahoo.com";
    $Subject = "Some one has signed up for your newsletter";
    $Email = Trim(stripslashes($_POST['Email']));

    // validation
    $validationOK=true;
    if (!$validationOK) {
    print "“;
    exit;
    }

    // prepare email body text
    $Body .= “Email: “;
    $Body .= $Email;
    $Body .= “n”;

    // send email
    $success = mail($EmailTo, $Subject, $Body, “From: < $EmailFrom>“);

    // redirect to success page
    if ($success){
    print ““;
    }
    else{
    print ““;
    }
    ?>

    Any help would be appreciated, not a PHP wizard. In case you need it the website is trading-strategy.com, and it is currently down right now because said client made a boo-boo.

    # December 7, 2009 at 2:28 am

    try this..not a php expert either. might work

    Code:
    < ?php

    $EmailFrom = "site@trading-strategy.com";
    $EmailTo = "jdtrader21@yahoo.com";
    $Subject = "Some one has signed up for your newsletter";
    $Email = Trim(stripslashes($_POST['Email']));

    // validation
    $validationOK=true;
    if (!$validationOK) {
    print "“;
    exit;
    }

    // prepare email body text
    $Body .= “Email: “;
    $Body .= $Email;
    $Body .= “n”;

    // send email
    $success = mail($EmailTo, $Subject, $Body, “From: < $EmailFrom>“);

    // redirect to success page
    if ($success){ ?>

    < ?php }
    else { ?>

    < ?php }
    ?>

    Rob
    # December 7, 2009 at 2:44 am

    What you want to use is:

    Code:
    // redirect to success page
    if ($success){
    header(“location: http://trading-strategy.com/“);
    }
    else{
    header(“location: error.htm”);
    }
    # December 15, 2009 at 6:14 pm

    This is a little wordpress quirk. Basically, except for the styles, referencing static files in your html doesn’t work properly when they reside in the theme directory. So instead, what you have to do is use this template tag

    Code:
    < ?php bloginfo(’template_directory’); ?>

    to denote the root of the theme directory, and then write the rest of your url from there.

    *Edit* I re-read your post and initially misunderstood. Robski is right, you’ll want to use header redirects.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".