我对从PHP更改为使用Jquery / Ajax的表单有语法错误。我正在尝试测试表单是否有效并提交以重置密码。
我一直收到以下错误
语法错误, /home/a4358077/public_html/mod/forgotajax.php中的意外$结尾 在 38
行我的代码是 -
<?php
require_once('../inc/autoload.php');
$objForm = new Form();
$objValid = new Validation($objForm);
$objUser = new User();
// forgot password form
if ($objForm->isPost('email')) {
$objValid->_expected = array('email');
$objValid->_required = array('email');
$email = $objForm->getPost('email');
if (empty($email) || !$objValid->isEmail($email)) {
$objValid->add2Errors('email');
} else {
$user = $objUser->getByEmail($email);
if (!empty($user)) {
if ($objValid->isValid()) {
if ($objUser->forgotUser($user)) {
$url = !empty($url) ? $url : '/?page=forgotsuccess';
echo json_encode(array('error' => false, 'url' => $url));
} else {
$url = !empty($url) ? $url : '/?page=forgot-failed';
//$message = 'Error in registration, Please contact administrator'; // failure
$objValid->add2Errors('login');
echo json_encode(array('error' => true, 'validation' => $objValid->_error_messages));
}
} else {
echo json_encode(array('error' => true));
}
我已经尝试修复代码,但无法确定在哪里放置大括号。
非常感谢任何帮助。
由于
答案 0 :(得分:1)
您的代码在上面的示例中不完整,或者缺少大量的花括号。
if ($objForm->isPost('email')) {
$objValid->_expected = array('email');
$objValid->_required = array('email');
$email = $objForm->getPost('email');
if (empty($email) || !$objValid->isEmail($email)) {
$objValid->add2Errors('email');
} else {
$user = $objUser->getByEmail($email);
if (!empty($user)) {
if ($objValid->isValid()) {
if ($objUser->forgotUser($user)) {
$url = !empty($url) ? $url : '/?page=forgotsuccess';
echo json_encode(array('error' => false, 'url' => $url));
} else {
$url = !empty($url) ? $url : '/?page=forgot-failed';
//$message = 'Error in registration, Please contact administrator'; // failure
$objValid->add2Errors('login');
echo json_encode(array('error' => true, 'validation' => $objValid->_error_messages));
}
} else {
echo json_encode(array('error' => true));
}
}
}
}