Jump to content

Recommended Posts

<html>

<body>
<form action="oldinsert.php" method="post">
<table border="1">



<tr><td>Username:</td> <td> <input type="text" name="username" /></td></tr>
<tr><td>Password:</td> <td> <input type="text" name="password" /></td></tr>
<tr><td>IC Number:</td> <td> <input type="text" name="ic" /></td></tr>
<tr><td>Full name:</td> <td><input type="text" name="fullname"/></td></tr>
<!--<tr><td>Gender:</td> <td> <input type="text" name="gender" /></td></tr>-->

<tr><td>Gender</td><td>
<select name="gender">
<option value="male">Male</option>
<option value="female">Female</option>
</select>
</td></tr>

<tr><td>Date of Birth:</td> <td> <input type="text" name="dob" /></td></tr>
<tr><td>Address:</td><td> <input type="text" name="address" /></td></tr>
<tr><td>Postcode:</td><td> <input type="text" name="postcode" /></td></tr>
<tr><td>City:</td><td> <input type="text" name="city" /></td></tr>
<tr><td>State:</td><td> <input type="text" name="state" /></td></tr>
<tr><td>Phone Number:</td><td> <input type="text" name="phonenumber" /></td></tr>
<tr><td>H/P Number:</td><td><input type="text" name="hpnumber" /></td></tr>
<!--<tr><td>Bank type:</td><td> <input type="text" name="banktype" /></td></tr>-->

<tr><td>Bank Type:</td><td>
<select name="banktype">
<option value="maybank">Maybank</option>
<option value="publicbank">Public Bank</option>
<option value="rhb">Rhb</option>
<option value="hsbc">Hsbc</option>
</select>
</td></tr>

<tr><td>A/C Name:</td><td> <input type="text" name="accname" /></td></tr>
<tr><td>A/C Number</td><td> <input type="text" name="accnumber" /></td></tr>

<tr><td><input type="submit" /></td></tr>

</table>

</form>
</body>

</html>

 

may i know how to add in validation to this form using php?

thanks.

Link to comment
https://forums.phpfreaks.com/topic/64384-solved-validation-of-form/
Share on other sites

Validation can involve lots of stuff, starting from empty fields, nr of characters, type of characters etc. Im just giving some points then im sure ull continue by yourself.

 

empty fields:

 

if($_POST['username'] == ""){
     echo "Please fill the username field";
}

 

nr of characters

 

if(strlen($_POST['password']) > 6 or strlen($_POST['password']) < 3){
    echo "The length of the password is incorrect";
}

 

type of characters

 

if(!is_numeric($_POST['phonenumber'])){
   echo "The phone number is invalid";
}

 

also u can use advanced methods to validate fields that have a specified format, like e-mail. Use regex in these cases:

 

if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) {
     echo "The e-mail is invalid"; //i suck at regex so i just copy pasted that regex (also use preg instead of eregi)
} 

 

Thats the basic idea of validation, which can be extended to a lot more. Just know what fields must be validated and how.

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.