Jump to content

Validation Errors display NULL?


Tenaciousmug

Recommended Posts

Ok I'm setting the error. I debugged my code and it's catching the phrase in the set_error() function. But it's returning NULL when I try to display it from the display_error() function. These functions are in the form class. I create a new instance of it on the register.php and I'm trying to grab the values. Here is my Form class (only showing the part you need to see):

 

class Form {
    private $error;
    
    public function set_error($errmsg){
        $this->error = $errmsg;
        return;
    }
    public function display_error() {
        $error = "<p style='color:red;'>".$this->error."</p>";
        return $error;
    }
}

 

Then here is my register process:

if(isset($_POST['submit'])) {
    if(isset($_POST['name']) && isset($_POST['username']) && isset($_POST['password']) && isset($_POST['password2']) && isset($_POST['email']) && isset($_POST['email2']) && isset($_POST['dob']) && isset($_POST['gender']) && isset($_POST['security'])) {
        if ($user->register_user($_POST['name'], $_POST['username'], $_POST['password'], $_POST['password2'], $_POST['email'], $_POST['email2'], $_POST['dob'], $_POST['gender'], $_POST['security'])) {
            $message = "User has been registered successfully.";
        }
        else {
            $message = $form->display_error();
        }
    }
    else {
        $message = "Please fill out all parts of the form!";
    }
}

 

It display the $message just fine when I call isset($message), but it won't display it when I assign it the form->display_error() value because it returns NULL.

 

Thank you!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.