We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

refresh a form when clicking on back

Hi I have a problem position data from the database in my view and that every time they enter the form but these not refreshed every you see someone gives you click the button back browser are generated, because I are doubling certain unique data .

How refresh the view when clicking the back button.?



93.7k
Accepted
answer
edited Oct '16

Hey, this is more of frontend problem, rather than Phalcon (backend) one. You can hack it with javascript: https://stackoverflow.com/questions/8861181/clear-all-fields-in-a-form-upon-going-back-with-browser-back-button

You can add CSRF token protection to your form with Phalcon. This way if user submits form twice it will not validate. But this will not cover the case of user pressing back button on browser, you have to use above link. Quick example of CSRF protection in use:


// Template
<input type="hidden" name="{{ security.getTokenKey() }}" value="{{ security.getToken() }}"/>

// Controller
if ($this->request->isPost() AND $this->security->checkToken()) {

}