WordPress.org

Ready to get started?Download WordPress

Forums

Form submission redirect to homepage (2 posts)

  1. TC.K
    Member
    Posted 1 year ago #

    I created a custom search form to find the posts by make use of wp_query.

    The form action is redirect to a custom page template where the custom wp_query running. The search form is using get method to passing the variable.

    <form method="get"  id="customsearch" action="<?php echo get_page_link( 3180 ); ?>">
    //form input here.
    </form>

    Somehow, the form was not redirected to the desired page, instead it went to homepage, when the permalink structure set to default.

    If I set the permalink other structure, like Numeric or Post name, it goes to the correct page, but url broken in paginated page. Eg:
    First page:
    www.example.com/search-page/?stringtosearch=xxxx?formsubmit=submit
    to
    www.example.com/search-page/page/2/?formsubmit=submit (the GET data stripped)

    Any idea why this happened?

  2. TC.K
    Member
    Posted 1 year ago #

    Okay, Did some research, It seem I need to add query_vars to register the input name. But it still redirect me to the homepage after I registered the variables.

    I created i test form for this issues,like this:

    <form method="get"  id="text" action="<?php echo get_page_link( 3180 ); ?>">
    	<input type="text" name="testget" value="">
    	<input type="submit" class="submit" value="Search" alt="[Submit]" name="submit" title="Search" />

    and I register the variable into query_vars like this,

    function add_query_vars($aVars) {
    $aVars[] = 'testget';
    return $aVars;
    }
    add_filter('query_vars', 'add_query_vars');

    but still, it redirect to the homepage. Anyone know why is this happened?

Topic Closed

This topic has been closed to new replies.

About this Topic