public function setCsrfProtection($value)
    {
        $this->csrfProtection = (bool)$value;

        if (!$value) {
            $this->removeFieldByName('csrftoken');
        } else {
            $field = $this->getFieldByName('csrftoken');

            // if the field does not exists yet, lets add it.
            if ($field === null) {
                $submitted = $this->isSubmitted();

                // Add a hidden 'csrftoken' field.
                $field = $this->hiddenField('csrftoken');

                $field->addValidator(new CsrfValidator());

                if (!$submitted && !$field->getValue()) {
                    $field->setValue(CsrfValidator::generateToken());
                }
            }
        }

        return $this;
    }
public function setCsrfProtection($value)
    {
        $this->csrfProtection = (bool)$value;

        if (!$value) {
            $this->removeFieldByName('csrftoken');
        } else {
            $field = $this->getFieldByName('csrftoken');

            // if the field does not exists yet, lets add it.
            if ($field === null) {
                $submitted = $this->isSubmitted();

                // Add a hidden 'csrftoken' field.
                $field = $this->hiddenField('csrftoken');

                $field->addValidator(new CsrfValidator());

                if (!$submitted && !$field->getValue()) {
                    $field->setValue(CsrfValidator::generateToken());
                }
            }
        }

        return $this;
    }
public function setCsrfProtection ( $ value ) { $ this -> csrfProtection = ( bool ) $ value ; if ( ! $ value ) { $ this -> removeFieldByName ( 'csrftoken' ) ; } else { $ field = $ this -> getFieldByName ( 'csrftoken' ) ; // if the field does not exists yet, lets add it. if ( $ field === null ) { $ submitted = $ this -> isSubmitted ( ) ; // Add a hidden 'csrftoken' field. $ field = $ this -> hiddenField ( 'csrftoken' ) ; $ field -> addValidator ( new CsrfValidator ( ) ) ; if ( ! $ submitted && ! $ field -> getValue ( ) ) { $ field -> setValue ( CsrfValidator :: generateToken ( ) ) ; } } } return $ this ; }
Should we enable Cross Site Request Forgery protection?
If not given, we will use possible default settings.
If those are not set, we will enable it for POST forms.
Set the value for csrfProtection

@param bool $value
@return Form
Should we enable Cross Site Request Forgery protection? If not given we will use possible default settings . If those are not set we will enable it for POST forms . Set the value for csrfProtection