Skip to content

Commit

Permalink
CsrfCounterMeasure: Save calls to setRequired()' and setIgnore()'
Browse files Browse the repository at this point in the history
  • Loading branch information
lippserd committed Oct 6, 2014
1 parent 8106fe4 commit 9db76bf
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions library/Icinga/Web/Form/Element/CsrfCounterMeasure.php
Expand Up @@ -4,16 +4,16 @@

namespace Icinga\Web\Form\Element;

use Zend_Form_Element_Xhtml;
use Icinga\Web\Session;
use Icinga\Web\Form\FormElement;
use Icinga\Web\Form\InvalidCSRFTokenException;

/**
* CSRF counter measure element
*
* You must not set a value to successfully use this element, just give it a name and you're good to go.
*/
class CsrfCounterMeasure extends Zend_Form_Element_Xhtml
class CsrfCounterMeasure extends FormElement
{
/**
* Default form view helper to use for rendering
Expand All @@ -22,14 +22,26 @@ class CsrfCounterMeasure extends Zend_Form_Element_Xhtml
*/
public $helper = 'formHidden';

/**
* Counter measure element is required
*
* @var bool
*/
protected $_ignore = true;

/**
* Ignore element when retrieving values at form level
*
* @var bool
*/
protected $_required = true;

/**
* Initialize this form element
*/
public function init()
{
$this->setRequired(true); // Not requiring this element would not make any sense
$this->setIgnore(true); // We do not want this element's value being retrieved by Form::getValues()
$this->setDecorators(array('ViewHelper'));
$this->addDecorator('ViewHelper');
$this->setValue($this->generateCsrfToken());
}

Expand Down

0 comments on commit 9db76bf

Please sign in to comment.