Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The standard FormSubmit view helper will always output with a name attribute, so I created another helper to output "anonymous" submit buttons. This is also the first #dailygist, where I aim to post a useful gist on Twitter each day for no reason other th
<?php
/**
* Helper to generate a "submit" button without a name attribute
*
* @category Noginn
* @package Noginn_View
* @subpackage Helper
*/
class Noginn_View_Helper_FormSubmitAnonymous extends Zend_View_Helper_FormElement
{
public function formSubmitAnonymous($name, $value = null, $attribs = null)
{
$info = $this->_getInfo($name, $value, $attribs);
extract($info); // name, value, attribs, options, listsep, disable
// check if disabled
$disabled = '';
if ($disable) {
$disabled = ' disabled="disabled"';
}
// XHTML or HTML end tag?
$endTag = ' />';
if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
$endTag= '>';
}
// Render the button.
$xhtml = '<input type="submit"'
. ' id="' . $this->view->escape($id) . '"'
. ' value="' . $this->view->escape($value) . '"'
. $disabled
. $this->_htmlAttribs($attribs)
. $endTag;
return $xhtml;
}
}
<form method="get" action="/search">
<dl class="zend_form">
<dt class="button">
<input type="submit" id="search" value="Search">
</dt>
</dl>
</form>
<!--
Now when the form is submitted we don't have "?search=Search" in our query string!
-->
<?php
$form = new Zend_Form();
$form->addElement('submit', 'search', array(
'label' => 'Search',
'ignore' => true,
'decorators' => array(
array('ViewHelper', array('helper' => 'FormSubmitAnonymous')),
array('HtmlTag', array('tag' => 'dt', 'class' => 'button')),
)
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.