我正在尝试使用 CakePHP 2.1 框架、jQuery 和 Cake 的 JsHelper 设置邀请请求页面,以便提交用户电子邮件,然后发出响应。理想情况下,我希望在电子邮件成功提交后让表单淡出,不幸的是,当使用“成功”或“完成”回调时,即使遇到验证错误,它也会淡出。
我的 view.ctp 代码:
<?php $this->Js->get('#InvitationRequestAddForm'); ?>
<?php $this->Js->event(
'submit',
$this->Js->request(
array(
'controller'=>'InvitationRequests',
'action'=>'add'
),
array('async' => true,
'method' => 'POST',
'dataExpression'=>true,
'update' => '#invitationStatus',
'complete' => "$('#InvitationRequestAddForm').fadeOut();",
'data'=> $this->Js->serializeForm(
array(
'isForm' => true,
'inline' => true
)
)
)
)
); ?>
我的控制器代码:
if($this->RequestHandler->isAjax())
{
if ($this->request->is('post'))
{
$this->InvitationRequest->create();
if ($this->InvitationRequest->save($this->request->data))
{
$this->set('alert_state', 'alert-success');
$this->set('message', '<strong>Hang Tight!</strong> We have your request and we are working hard to approve as soon as possible!');
}
else
{
$this->set('alert_state', 'alert-error');
$this->set('message', '<strong>Uh Oh!</strong> Something went wrong, check your email address and please try again.');
}
}
}
非常感谢任何帮助/建议!