-2

I am having a syntax error for a form I have changed from PHP to using Jquery/Ajax. I am trying to test if form will work and submit to reset the password.

I keep getting the below error

syntax error, unexpected $end in /home/a4358077/public_html/mod/forgotajax.php on line 38

My code is -

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

I have tried fixing the code but cannot figure out where to either put a curly brace.

Any help is much appreciated.

Thanks

qakbar
  • 53
  • 1
  • 5

1 Answers1

1

Your code is either incomplete in your example above, or missing a ton of curly brackets.

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));
            }
        }
    }
}
Blake
  • 2,294
  • 1
  • 16
  • 24
  • Obviously I don't know the logic of what OP is trying to do, but at least this is valid code. – Blake Sep 17 '16 at 15:16