Zend Avoid Submit Button Values ​​in GET Parameters in URL

I have a form created using Zend_Form, with the = GET method used to search for records with elements, as shown below:

[form] username [input type = "text" name = "uname"] [input type = "submit" value = "Search" name = "search"] [/ Form]

After submitting the form, all GET parameters along with the submit button value appear in the URL.

http://mysite.com/users/search?uname=abc&search=Search

How to avoid submit button value appearing in url? Is routing a routine?

+3
source share
5 answers

, , ( ) .

:

$params = $this->getRequest()->getParams();
if isset($params['search'])
  unset($params['search']);
  return $this->_helper->Redirector->setGotoSimple('thisAction', null, null, $params);

handle form here

, Post/Redirect/Get, , ( ) , , - ( Wiki- ).

, . IMO -.

0

, name,

$submit = new Zend_Form_Element_Submit('search')->setAttrib('name', '');

a Zend_Form

// Input element
$submit = $this->createElement('submit', 'search')->setAttrib('name', '');

// Or Button element
$submit = $this->createElement('button', 'search')->setAttribs(array
(
    'name' => '', 'type' => 'submit',
);
+4

, GET/POST.

, , GET, , , . , , "submit", , .

Zend_View_Helper_FormSubmit, , submit . , "submit" .

$element->setAttribs( array('helper' => 'My_Helper_FormSubmit') );
+3

Then create your own form element class and remove the name attribute from the element using preg_replace. Its beauty lies in the fact that it will not interfere with other decorators.

So something like this:

class My_Button extends Zend_Form_Element_Submit
{
    public function render()
    {
        return preg_replace('/(<input.*?)( name="[^"]*")([^>]*>)/', "$1$3", parent::render(), 1);
    }
}
+1
source

You can remove the name attribute for the submit button in javascript. JQuery example:

$('input[name="submit"]').removeAttr('name');
+1
source

Source: https://habr.com/ru/post/1764105/


All Articles