我正在尝试在产品页面中添加表单以请求其他信息.它是名称,国家,电子邮件和问题字段的简单形式.
我创建了这个教程,但我不喜欢只需要小型表格的想法我需要制作新的模型和控制器.
所以我在view.ctp中添加表单
print $this->Form->create('', array('action' => 'sendemail'));
print $this->Form->input('name',array('label' => __('Name',true).':'));
print $this->Form->input('country',array('label' => __('Country',true).':'));
print $this->Form->input('email',array('label' => __('E-mail',true).':'));
print $this->Form->input('question',array('type' => 'textarea', 'label' => __('Your question',true).':'));
print $this->Form->end(__('Send', true));
Run Code Online (Sandbox Code Playgroud)
并添加功能sendemail在products_controller.php
function sendemail(){
if(!empty($this->data)){
if($this->data['Product']['name'] && $this->data['Product']['country'] && $this->data['Product']['email'] && $this->data['Product']['question']){
// sending email
$this->Session->setFlash(__('Thanks, your qustion was send.', true), 'default', array('class' => 'message status'));
$this->redirect($this->referer());
} else {
// validation
$this->Session->setFlash(__('Fill all fiels', true), 'default', array('class' => 'message error'));
$this->redirect($this->referer());
}
} else …Run Code Online (Sandbox Code Playgroud) 我有一个AJAX控制器,可以处理CakePHP网站上所有与AJAX相关的调用.其中一个AJAX调用是发送电子邮件,该函数不会与数据库进行任何数据交换.我仍然希望能够在执行此AJAX电子邮件时验证电子邮件地址等内容,但我不确定如何使用CakePHP进行此操作.我可以直接访问验证功能还是有其他/更好的方法?
谢谢!