Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2004
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    form validation problem - urgent plz help

    hi,

    i have been trying to implement the form validation, in which the user is shown error in RED (or any) color next to the textbox or any input box in the next page, if he or she does not enter or enters wrong information.

    I am trying to implement the validation similar to what happens when a user registers for an account for Yahoo Mail. He/she is shown the only fields which are left out or inputted wrong.

    NOTE: i am using smarty templating system.

    Plz help me finding a code snippet or some tutorial.

    Thanx
    Gaurav

  • #2
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,072
    Thanks
    4
    Thanked 8 Times in 8 Posts
    something similar to this?


    submit.html
    Code:
    <form method=post action=input.php>
    <table>
      <tr>
        <td>Name <input type=text name="name" ></td>
        <td></td>
      </tr>
      <tr>
        <td>Email <input type=text name="Email"></td>
        <td></td>
      </tr>
      <tr>
        <td colspan=2> <input type=submit value="submit"></td>
      </tr>
    </table>
    </form>

    input.php
    PHP Code:
    <?php
    $name 
    $_POST['name'];
    $email $_POST['email'];
    if(!
    $name) || (!$email){
      echo 
    "<form method=post action=input.php>\n";
      echo 
    "<table>\n\t<tr>\n";
      if(!
    $name){
      echo 
    "\t\t<td>Name <input type=text name=\"name\" ></td>\n";
      echo 
    "\t\t<td><font color=red>Missing Name</font>";
      echo 
    "<input type=hidden name=\"email\" value=\"".$email."\"></td>\n\t<tr>\n";
      }
      if(!
    $email){
      echo 
    "\t\t<td>Email <input type=text name=\"email\" ></td>\n";
      echo 
    "\t\t<td><font color=red>Missing Email</font>";
      echo 
    "<input type=hidden name=\"name\" value=\"".$name."\"></td>\n\t<tr>\n";
      }
      echo 
    "\t<tr>\n\t\t<td colspan=2>";
      echo 
    "<input type=submit value=\"submit\"></td>\n";
      echo 
    "\t</tr>\n</table>\n</form>";
    }
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •