Performing a POST action on homepage goes to posts page

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.

Read More

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;

}

Related posts

2 comments

  1. 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.

  2. 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.

Comments are closed.