1

On every page of my site I got a contact form that will send an email to the respective address. On this site also I've set the front page display to a static page.

The contact form will basically post to self and if successful will take the user to a new page, otherwise will anchor down to the contact form and display the error. But on the home page, be it any type of POST request, it will set the page to the posts page. Seems bizarre to me as it can be an empty POST request and still take the user back to the posts page but the URL won't change. This only happen if you do a POST to the homepage, all other pages work as expected.

Any ideas?

add_action( 'wp_head', 'process_contact_form' );
function process_contact_form() {

    if( isset( $_POST['submit'] ) && $_POST['submit'] ) {
        echo'test';
    }

}

add_shortcode( 'mini-contact', 'get_mini_contact' );
function get_mini_contact( $atts = array() ) {

    extract(shortcode_atts(array(
        'title'   => 'Contact US',
        'button'  => 'Submit',
        'label'   => 'Message us',
        'subject' => 'Message'
    ), $atts));

    $html  = '';

    $html .= '<section id="quick-contact-form" class="home-solution">';
        $html .= '<div class="container">';
            $html .= '<header>';
                $html .= '<h2 class="aligncenter  type--bottom-space">' . $title . '</h2>';
            $html .= '</header>';

            $html .= '
                <form class="contact-form" method="post" action="">
                    <div class="row">
                        <div class="medium-5  columns">
                            <label>Name</label>
                            <input type="text" name="name" class="form-contact__text" />
                        </div>
                        <div class="medium-5  columns">
                            <label>E-mail</label>
                            <input type="text" name="email" class="form-contact__text" />
                        </div>
                    </div>
                    <div class="row">
                        <div class="medium-10  columns">
                            <label>Share your business problem today</label>
                            <textarea name="comment" rows="20" class="form-contact__textarea"></textarea>
                        </div>
                    </div>
                    <div class="row">
                        <div class="medium-10  columns">
                            <input type="submit" name="submit" value="' . $button . '" class="button  expand">
                        </div>
                    </div>
                    <input type="hidden" name="subject" value="' . $subject . '">
                </form>
            ';

        $html .= '</div>';
    $html .= '</section>';

    return $html;

}
1
  • What are you front-page settings in Settings -> Reading? What are Front page displays, Front page, and Posts page? Commented Feb 24, 2014 at 16:32

2 Answers 2

4

When posting a form, if you use 'name' as an input name then there seems to be a problem with submitting.

Try changing:

<input type="text" name="name" class="form-contact__text" />

to:

<input type="text" name="the_name" class="form-contact__text" />

Also, best to give your submit button a more unique name in case it conflicts with any plugins/themes - then check for the submission of that in your process_contact_form() function.

1
  • How weird, it worked though. Any ideas on why it only affects the homepage?
    – WolfieZero
    Commented Feb 24, 2014 at 16:36
1

This may be a bit old but this post helped me find a similar issue. If you have an input name='search' it will also load a post page instead of reloading the static front page.

1
  • "This may be a bit old but this post helped me find a similar issue. If you have an input name='search' it will also load a post page instead of reloading the static front page." aha! This just helped me debug why my homepage form was redirecting to posts. The "search" input value was triggering it.
    – jane doe
    Commented Jul 14, 2021 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.