Ajax忘记密码错误语法


Ajax forgot password error syntax

我有一个语法错误的形式,我已经从PHP改为使用Jquery/Ajax。我正试图测试表单是否会工作,并提交重置密码。

我一直得到下面的错误

语法错误,$end in /home/a4358077/public_html/mod/forgotajax.php on line 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));   
}

我试过修复代码,但不知道在哪里放大括号。

任何帮助都是非常感激的。

谢谢

在上面的例子中,你的代码要么不完整,要么缺少大量的花括号。

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));
            }
        }
    }
}