views:

344

answers:

2

If I build a form:

        $search_words = new Zend_Form_Element_Text('text');
 $search_words->setRequired(true)->setDecorators(array(array('ViewHelper')));
 $form->addElement($search_words);

 $go =  new Zend_Form_Element_Submit('gogogo');
 $go->setDecorators(array(array('ViewHelper')))
    ->setIgnore(true);
 $form->addElement($go);

With method GET. I will see in the URL gogogo=gogogo. If I was writing the markup myself, I simply wouldn't give the submit any [name] attribute and that would have solved that. Trying to set the name of a submit to '' won't work (either throws an exception or is being ignored, depends on the way you do it).
Any (built in) ideas?

A: 

There are a few possible options:

  1. Use a custom decorator to build the markup, so a name attribute is not specified
  2. Use a string replacement function on the markup returned by Zend_Form's render methods, to remove the attribute
  3. What I often do, as follows

I usually add a custom route so that either of the following is valid:

 domain.tld/search/keyword
 domain.tld/search?q=keyword

Then you can use javascript to redirect to the cleaner form of the URL, taking care to urlencode the keyword field

Most of your users will see the cleaner URL this way.

David Caunt
+1  A: 

Another possibility would be to disable the submit button before the form is submitted:

$go->setDecorators(array(array('ViewHelper')))
   ->setIgnore(true)
   ->setAttrib('onclick', 'this.disabled = true');

This way, the value of the submit button will be ignored upon submitting the form.

Pieter