php - Display errors next to input fields -


i know there whole lot of questions regarding same issue, i'm stuck it. have hard time getting what's wrong. have tried many things google, no luck. trying have validation errors showing next relevant input fields instead of being displayed @ form top. form quite big i'll post "sample" of it.

html form:

<form action="register.php" method="post">     <table>         <th class="topline">             <label for="form_login" >login         </th>          <td>             <div class="form_input_bg">                 <input type="text" name="username" value="" maxlength="16" size="16"/>                 <?php echo $username;?>             </div>         </td>     </tr>       <tr>         <th class="topline">password             <p style="font-size:9px;">8-16 character (only a-z,0-9)</p>         </th>         <td>             <div class="form_input_bg">                 <input type="password" name="pass" value="" maxlength="16" size="16"/>             </div>         </td>     </tr>     <tr> 

and php validation, happens this, still sample of (don't wanna hurt eyes).

<?php     elseif(strlen($_post['username']) < 5)     {         echo '<div class="message">username must longer 4 characters               </div></div><p> ?> 

i suggest separate validation displaying html this:

// validation $error = array(); if (strlen($username) < 5)     $error['username'] = 'login must longer 4 characters';   // html <input type="text" name="username" value="" maxlength="16" size="16"/><?php echo $username;?> <?php if (isset($error['username'])) : ?>     <p class="error"><?php echo $error['username'] ?></p> <?php endif ?> 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -