Jump to content

How do i style and position the error messages my php code gives out on my page?


pappakaka

Recommended Posts

I have finally gotten my registration form to work on my website but i have another question! When for example someone registers at my website and type in the wrong email address, i've set php to give out an error message like "Please enter a valid email address". But that message shows up at the verry top-left corner of my page and makes some objekts move around on my page and you can't click in the <input> fields anymore . How could i make those error messages show up above my registration form at the top of my site and maybe style them with a border and maybe make the text red and so that it doesnt change anything on my page? could i use css for that somehow or what?

 

This is how i show the error messages right now:

  public function show_errors()
  {
    echo "<h3>Errors</h3>";

    foreach($this->errors as $key=>$value)
      echo $value."<br>";
  }

  public function valid_data()
  {
    if($this->user_exists())
      $this->errors[] = 'Username already taken, choose another one!';
    if(empty($this->username))
      $this->errors[] = 'Please enter a valid username!';
if(empty($this->first_name))

 

 

Link to comment
Share on other sites

Random thoughts..

1. if you have a blank area on your form large enough to hold all possible error messages, you could have an IF statement, where if error then show div else don' show div

 

2. you could have an if statement next to or under each field, where if error show else don't

 

3. you could have an if statement, where if error ONLY the error fields are shown - may need to place good filed values in hidden fields or session variables.

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.