Grow your CSS skills. Land your dream job.

Why my contact form is going to a different page?

  • # April 29, 2013 at 10:01 am

    Hi , I m creating a website on wordpress, and I didn’t want to use a plugin for contact us so I thought I should create my own. But I m having a problem. When you fill the form it is going to a different page even though action=”” however if the form is empty is lands up to the same page and also send a blank email.
    But why is it going to a different page when I enter information in the form.

    http://mstoicthemes.com/duchi/

    And here is the code

    < ?php
    if(isset($_POST)){

    $name= $_POST;
    $email= $_POST;
    $subject= $_POST;
    $comments= $_POST;

    $emailTo = ‘sayed2x2@gmail.com';
    $subject = $name.’ sent you this message from your website.';
    $body = “Name: $name: $email: $comments”;
    $headers = ‘From: My Site < '.$emailTo.'>‘ . “rn” . ‘Reply-To: ‘ . $email;

    $mailsent = mail($emailTo, $subject, $body, $headers);

    if($mailsent){
    echo “

    Thank you contacting us

    We will get back to you soon

    “;
    }else{
    echo “Your Email was not sent”;
    }

    }else{
    ?>

    else part


    Email:
    Subject:
    < ?php if(isset($_POST)): echo $_POST; endif ?>

    < ?php } ?>

    # April 29, 2013 at 11:51 am

    Anyone?

    # April 29, 2013 at 1:11 pm

    Is the processing / error handling apart of the same page? If so, try setting the action to #

    # April 29, 2013 at 1:52 pm

    I tried the same code outside of wordpress and it works, but its not working in wordpress dont know why I tried # in action but no luck
    I also tried < ?php echo bloginfo('home'); ?> in action, But when I use < ?php echo bloginfo('home'); ?> in action , it comes back to the same page, but it does not go to the if condition, To check I just echo “test”; but it didnt echo anything meaning its not even going inside my if condition ):

    # April 29, 2013 at 5:09 pm

    Do both blank and filled in form emails get send? I just tried both…. sorry for the spam :P

    I think that 301 redirect might be the problem… form action gets printed as `http://mstoicthemes.com/duchi`, however that causes a redirect to `http://mstoicthemes.com/duchi/` (losing the form data).

    # April 30, 2013 at 1:44 am

    Thanks for trying but what do I do? I still can’t find a way. I can stop that redirect, I will put < ?php echo bloginfo('home'); ?>
    in action, so now it would come back to the same page but its not going into the if condition.

    # May 15, 2013 at 3:32 am

    I also tried this code outside wordpress, it was working there but inside it was not working. I still don’t know what’s happening there. I think you need to discuss this with certified [Wordpress developer](http://techiesindiainc.com/wordpress “WordPress developer”).

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

You must be logged in to reply to this topic.

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