I’m trying to avoid forms being sent and saved multiple times to the database, for example, if the user click the submit button multiple times or refresh page
I saw two ways: prg pattern and form tokens whats the most recomended form? is there any cakephp 3 plugin for this?
Im using this add function to test without sucess the prg pattern:
public function add(){
$user = $this->Users->newEntity();
if ($this->request->is('post')) {
$user = $this->Users->patchEntity($user, $this->request->data);
if ($this->Users->save($user)) {
$this->Flash->success(__('User saved.'));
//$this->setAction('prg_add'); this could work maybe?
// thats it? or should i pass all the submited data via get to the prg_add action and then process the save() and redirect to index
return $this->redirect(['controller' => 'Users', 'action' => 'prg_add'], 303);
}
$this->Flash->error(__('User not saved.'));
}
$this->set('user', $user);
}
public function prg_add()
{
//what to do here? It would be part of the GET right?
return $this->redirect(['action' => 'index']);
}