php - Error Message Inline with Input -


this code error function

function output_errors($errors) {     return '<ul><li>' . implode('</li><li>', $errors) . '</li></ul>'; } 

this php code login

include 'core/init.php';  if (empty($_post) === false) {   $username = $_post['username'];   $password = $_post['password'];      if (empty($username) === true || empty($password) === true) {       $errors[] = 'enter valid username or password.';     }       elseif (user_exists($username) === false) {         $errors[] = 'user not exist.';       }       elseif (user_active($username) === false) {         $errors[] = 'please activate account first.';       }       else {          if (strlen($password) > 32) {           $errors[] = 'password long. <br>';         }          $login = login($username, $password);          if ($login === false) {           $errors[] = 'incorrect username or password.';         }           else {             $_session['user_id'] = $login; //login returns user_id               header('location: hashtagphotowall.php');             exit();           }         }      //visual representation of error arrays     //print_r($errors);  }   else {     $errors[] = 'no data received!';   }  if (empty($errors) === false) {   echo output_errors($errors); } 

this html code login form

<div id="firstmodal" class="reveal-modal" data-reveal aria-hidden="true" role="dialog">      <p class="modal-row"><em>sign in.</em><hr></p>      <a href="#" class="button small">connect facebook</a>      <p class="hr-enclosed">or login email</p>       <form action="login.php" method="post">        <div class="field-box">          <input type="text" name="username" placeholder="username:" />          <input type="password" name="password" placeholder="password:" />          <input type="submit" name="loginbutton" class="button small" value="login" />                              </div>      </form>     <p class="modal-row-sub">forgot password? <a href="#">here</a>.<br>new user? sign <a href="#" data-reveal-id="secondmodal">here</a>.</p>    <a class="close-reveal-modal" aria-label="close">&#215;</a> </div> 

the code functioning error messages display on webpage. tried declaring variable no value , echo inline input tag have no output. maybe it's because use error arrays incorrectly. on how can make error arrays inline input tags in login form? thank you

i think want test logic built same login.php file form displayed. way makes passing of data user easier.

(pseudo code)

add div top of form: `<div id="errors">output_errors($errors) </div>`  tells user do.  first time thru $errors = "" (or 1 space?)   error div invisible user.  if previous submission made, test data validity.  if previous submission made , input good, go on new page  (success_thank_you_for_your_submission.php)  if previous submission made, , input not valid,  redisplay page, errors on top of form. redisplay header("location:[login.php]");  should take time re-populate fields user submitted. sending empty form when there errors won't make folks happy. 

user keeps submitting form till right...


Comments