validation - How to start validating php form only after I clicked submit -


i new php , web development. trying simple validation of text field. want display red remark beside text field after submit button clicked.

however problem here is: php codes validates input field moment page loaded. how validate after user clicked submit button?

<form method="post" action="<?php echo htmlspecialchars($_server["php_self"]);?>">         name <input type='text' name='name' /><br>         email <input type='text' name='email' /><br>         age<input type='text' name='age' /><br>         <input type='submit' name='done' /><br><br> </form>  <?php     if(empty($post['name']))         echo '<font color="red">please enter name.</font>';     if(empty($post['email']))         echo '<font color="red">please enter email.</font>';     if(empty($post['age']))         echo '<font color="red">please enter age.</font>'; ?> 

i have several questions here:

1) if want display error message right beside each text field, shall write separate php code beside each input field?

2) how echo error message after user clicked submit button?

i know extremely many people here, first time doing related web.

just check if post send

<?php         if($_post)         {             if(empty($post['name']))                 echo '<font color="red">please enter name.</font>';             if(empty($post['email']))                 echo '<font color="red">please enter email.</font>';             if(empty($post['age']))                 echo '<font color="red">please enter age.</font>';         }     ?> 

Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -