我有一个简单的 cakephp 表单,带有提交到数据库的验证。它不需要登录用户。
不通过浏览器正常使用表单并且未填写所有必填字段会导致验证错误并且表单未提交。
但是,我似乎被某人/某事发送了垃圾邮件。他们填写的是通用的命名字段(姓名、电子邮件、消息等),而不是晦涩的字段,并且这些记录正在进入数据库,因此它们显然绕过了验证!
我的问题是如何???(我怎样才能阻止他们?)
我有一种感觉,我错过了一个明显的循环孔或其他东西......
这是我的添加方法:
function add() {
$this->pageTitle = 'Projects - Submit Project';
if (!empty($this->data)) {
$this->Project->create();
if ($this->Project->save($this->data)) {
$this->Session->setFlash(__('The Project has been saved', true));
$this->_sendStaffMail($this->Project->id);
$this->_sendClientMail($this->Project->id);
$this->redirect(array('controller' => 'pages', 'action'=>'thanks'));
} else {
$this->Session->setFlash(__('The Project could not be saved. Please, try again.', true));
}
}
}
并从模型验证:
var $validate = array(
'name' => array('notempty'),
'department' => array('notempty'),
'client' => array('notempty'),
'contact_name' => array('notempty'),
'email' => array('email'),
'phone' => array('notempty'),
'title' => array('notempty'),
'background' => array('notempty'),
'objectives' => array('notempty'),
'target_audience' => array('notempty'),
'message' => array('notempty'),
'logos' => array('notempty'),
'images' => array('notempty'),
'print_info' => array('notempty')
);
我还应该提到我曾尝试使用 Security 组件,但是当我的项目中包含大量表单时,它似乎已经过时了(尽管它们落后于 Auth 登录)