防止表单CakePHP 3上出现双post
我想防止双击submit按钮时出现重复发布 我有以下代码来保存数据:防止表单CakePHP 3上出现双post,cakephp,post,double,Cakephp,Post,Double,我想防止双击submit按钮时出现重复发布 我有以下代码来保存数据: public function reply($id = null){ date_default_timezone_set('Europe/Amsterdam'); date_default_timezone_set('UTC'); $username = $this->Auth->user('username'); $authorRang = $t
public function reply($id = null){
date_default_timezone_set('Europe/Amsterdam');
date_default_timezone_set('UTC');
$username = $this->Auth->user('username');
$authorRang = $this->Auth->user('rang');
$posts = TableRegistry::get('posts');
$threads = TableRegistry::get('threads');
$query = $threads->find('all');
$last_post_date = date('m/d/Y h:i:s a', time());
$replies = $posts->newEntity();
if ($this->request->is('post')) {
//$token = $this->request->getParam('_csrfToken');
$reply = $posts->patchEntity($replies, $this->request->data);
$reply['thread_id'] = $id;
$reply['author'] = $username;
$reply['created'] = $last_post_date;
$reply['authorRang'] = $authorRang;
$query->update()
->set(['last_post_date' => $last_post_date])
->where(['id' => $id])
->execute();
if ($posts->save($reply)) {
$this->Flash->success(__('Your reply has been saved.'));
//return $this->redirect(['action' => 'view/'.$id.'']);
}else{
$this->Flash->error(__('Unable to add your reply.'));
}
}
$this->set('reply', $replies);
}
我怎样才能预防它
我试过很多东西,但都不管用。我试图取消实体设置,但它不起作用。它仍然多次保存数据
谢谢