0
我試圖將google的reCaptcha添加到我的某個頁面。我一直在關注本教程https://codeforgeek.com/2014/12/google-recaptcha-tutorial/並完成了安裝和表單網站上的所有工作。然而,我堅持在PHP方面。我已經將數據存儲在數據庫中,然後發送電子郵件。我一直在嘗試各種方法將reCaptcha整合到現有的功能中,但沒有運氣。將reCaptcha代碼添加到php腳本(CakePhp)
public function calc() {
$this->set('title_for_layout', 'Fun Tests');
$this->set('meta_description', 'Check out these funny tests');
if(!$this->Session->check('isLoggedin'))
{
$this->Session->write('Temp.redirect_url', Router::url(null, true));
}
if(!isset($this->params['named']['u'])) {
$this->Session->setFlash(__(WRONG_ACCESS_MSG), 'default', array('class' => ERROR_CLASS));
$this->redirect(array('controller' => 'pages', 'action' => 'home'));
}
//echo $this->Session->read('Temp.redirect_url');
//get the link detail
$this->loadModel('User');
$actual_user_id = $this->params['named']['u'] - Configure::read('Site.prefix_to_add_in_userid');
//echo $actual_user_id;
$sender_array = $this->User->find('first', array('conditions' => array('User.id' => $actual_user_id)));
if(empty($sender_array)) {
$this->Session->setFlash(__(WRONG_ACCESS_MSG), 'default', array('class' => ERROR_CLASS));
$this->redirect(array('controller' => 'pages', 'action' => 'home'));
}
$this->set(compact('sender_array'));
if(!empty($this->request->data)) {
$this->{$this->pm}->set($this->request->data);
if ($this->{$this->pm}->validates()) {
$this->{$this->pm}->create();
$this->request->data['Result']['user_id'] = $this->Session->read('Auth.User.id');
if ($this->{$this->pm}->save($this->request->data, true)) {
$this->Session->setFlash(ADD_MSG, 'default', array('class' => SUCCESS_CLASS));
//send email to the User who created this link if he has the get_notifications flag set to 1
if($sender_array['User']['get_notifications'] == 1) {
$Email = new CakeEmail();
$Email->to($sender_array['User']['email']);
$Email->subject(__('New Results For Your Test', Configure::read('Site.title')));
$Email->viewVars(array('data' => $sender_array['User']));
$Email->template('Tested_successfully', 'default');
$email_pars = array('email' => $Email);
$this->centralEmail($email_pars);
}
$this->render('result_saved');
//$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(ERROR_MSG, 'default', array('class' => ERROR_CLASS));
}
} else {
// didn't validate logic
$errors = $this->{$this->pm}->validationErrors;
$this->Session->setFlash(ERROR_VALIDATE_MSG, 'default', array('class' => ERROR_CLASS));
}
}
$this->set('title_for_layout', 'Fun Tests');
$this->set('meta_description', 'Check out these funny tests');
}
請檢查cakephp插件https://github.com/CakeDC/recaptcha –