我有一个小问题,我不知道如何解决。Ajax 验证通过 zend 完美运行。按下提交按钮确实有效,但是当我得到正确的电子邮件和密码时,它不会进入用户页面。它只是保留在那个表格上。我知道这与return false
通过true
Ajax 提交有关。
有人可以帮我解决这个问题。如果在验证中没有检测到错误,我不知道如何return true
提交。
这是我的代码:Ajax 和 Javascript
$(function() {
$('input').blur(function() {
var formElementId = $(this).get(0).id;
doValidation(formElementId);
});
});
**$(function() {
$('#btn_login').click(function() {
var email = document.getElementById('email').id;
var password = document.getElementById('password').id;
doValidation(email);
doValidation(password);
return false;
});
});**
function doValidation(id) {
var url = '/users/validationform';
var data = {};
$('input').each(function() {
data[$(this).attr('name')] = $(this).val();
});
$.post(url,data,function(resp) {
$("#" + id).parent().find('.errors').remove();
$("#" + id).parent().append(getErrorHtml(resp[id], id));
}, 'json');
}
function getErrorHtml(formErrors, id) {
var o = '<div id="login-error" style="color:red"><ul id="errors-'+id+'" class="errors" style="list-style-type:none;">';
for(errorKey in formErrors) {
o += '<li>- ' + formErrors[errorKey] + '</li>';
}
o += '</ul></div>';
return o;
}
Zend 控制器:
public function validationformAction()
{
$loginForm = new Application_Form_UserLogin();
$loginForm->isValidPartial($_POST);
header('Content-type: application/json');
$this->_helper->json($loginForm->getMessages());
}
public function loginFormAction()
{
$this->_helper->layout()->disableLayout();
//$this->_helper->viewRenderer->setNoRender(true);
$email = $this->getRequest()->getParam('email');
$password = $this->getRequest()->getParam('password');
$loginForm = new Application_Form_UserLogin();
if ($this->getRequest()->isPost())
{
/************ Login Form ************/
if ($loginForm->isValid($this->getRequest()->getParams()))
{
$user = $this->_helper->model('Users')->createRow($loginForm->getValues());
$user = $this->_helper->model('Users')->fetchRowByFields(array('email' => $email, 'hash' => $password));
if($user)
{
Zend_Session::rememberMe(86400 * 14);
Zend_Auth::getInstance()->getStorage()->write($user);
$this->getHelper('redirector')->gotoRoute(array(), 'invite');
return;
}
else {
// Error message
$this->view->errorMsg = "<b>password</b> - invalid, please try again! *";
}
}
else
{
// something
}
}
$this->view->loginForm = $loginForm;
}