G
G
gachkydxvbgd2017-07-29 19:51:32
Phalcon
gachkydxvbgd, 2017-07-29 19:51:32

How to do csrf phalcon validation?

How to do token validation in Phalcon 3.2 form
In documentation like this

if ($this->request->isPost()) {
            if ($this->security->checkToken()) {
                // The token is OK
            }
        }

The form
$csrf = new Hidden('csrf',
        [
        'name'  => $this->security->getToken(),
            'value'   => $this->security->getToken(),
        ]
    );

        $csrf->addValidator(new Identical([
           // $this->security->checkToken()
            
        ]));
        $csrf->clear();
        $this->add($csrf);

        $this->add(new Submit('go', [
            'class' => 'btn btn-success'
        ]));

{{ form('class': 'form-search') }}
    <p>
    {{ form.render('csrf') }}
    </p>   
    <p>
        {{ form.render('go') }}
    </p>

</form> 
{{dump(this.request.getPost())}}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question