Make it possible to disable form identification

refs #5525
This commit is contained in:
Johannes Meyer 2014-09-05 09:16:09 +02:00
parent 439d1895a7
commit 8846f17ae1
1 changed files with 45 additions and 8 deletions

View File

@ -67,6 +67,13 @@ class Form extends Zend_Form
*/
protected $tokenElementName = 'CSRFToken';
/**
* Whether this form should add a UID element being used to distinct different forms posting to the same action
*
* @var bool
*/
protected $uidDisabled = false;
/**
* Name of the form identification element
*
@ -236,6 +243,34 @@ class Form extends Zend_Form
return $this->tokenElementName;
}
/**
* Disable form identification and remove its field if already added
*
* @param bool $disabled Set true in order to disable identification for this form, otherwise false
*
* @return self
*/
public function setUidDisabled($disabled = true)
{
$this->uidDisabled = (bool) $disabled;
if ($disabled && $this->getElement($this->uidElementName) !== null) {
$this->removeElement($this->uidElementName);
}
return $this;
}
/**
* Return whether identification is disabled for this form
*
* @return bool
*/
public function getUidDisabled()
{
return $this->uidDisabled;
}
/**
* Set the name to use for the form identification element
*
@ -398,14 +433,16 @@ class Form extends Zend_Form
*/
public function addFormIdentification()
{
$this->addElement(
'hidden',
$this->uidElementName,
array(
'ignore' => true,
'value' => $this->getName()
)
);
if (false === $this->uidDisabled && $this->getElement($this->uidElementName) === null) {
$this->addElement(
'hidden',
$this->uidElementName,
array(
'ignore' => true,
'value' => $this->getName()
)
);
}
return $this;
}