+1 vote
in Other by
i have following html

<form method="post" action="" id="formsearch">

    <table>

        <tr>

            <td>Keyword</td>

            <td><input type="text" name="search" id="search" value="<?php echo $this->search?>" /></td>

            <td><input type="submit" value="Search" /></td>

        </tr>

    </table>

    </form>

When i press submit i wish the url should be

domain.com/users/index/search/{search_word}. And need pagination also.

domain.com/users/index/page/2/search/{search_word}

How should be it possible

JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
In the form, change method="post" to method="get". This will not set the url as you want, however it will put the search into the url as a query: domain.com/users/?search=my+keyword+here&submit=Search

Alternatively, have you controller redirect the form once it has been received to this url structure?

//controller

if($this->getRequest()->isPost() and $form->isValid($this->getRequest()->getPost())

{

  $this->_helper->redirecter->gotoRouteAndExit(array('search' => $form->getData('search')), 'searchRoute');

}

This is just an example. What it is doing, is checking if the form has been submitted (via post - no changes needed to your form). If the form is valid then redirect to another url. The first parameter of gotoRouteAndExit is an array of parameters; in this case the parameter name is 'search' and the value is gotten out of the form. You will need to create the route (in this code it is named searchRoute) in your bootstrap file.

Related questions

+1 vote
asked Jan 30, 2022 in Other by DavidAnderson
+1 vote
asked Jan 30, 2022 in Other by DavidAnderson
...