views:

44

answers:

3

Hai.. i already added javascript validation for my form.Its working fine.But mean while i ve to validate the same form using PHP also.

This is the form code:

  class airportclass{
    function add_airport_frm(){
    $errmsg=0;
<table>
  <form action="" method="post" name="airport" >
  <tr> <td colspan="2" align="center"><?php echo $errmsg; ?></td></tr>

    <tr>
      <td><strong>Code :</strong></td>
      <td><input type="text" name="code" id="code"   /></td>
    </tr>
    <tr>
      <td><strong>Name:</strong></td>
      <td><input type="text" name="name" id="name"   /></td>
    </tr>
    </form>
</table>        
    }

This is the PHP script in another file :

 if(isset($_POST['postcode']) && $_POST['postcode']!="")
{
$code=$_POST['code'];
$name=$_POST['name'];
$postcode=$_POST['postcode'];
$auth=$_POST['auth'];

 if(trim($code)=='')
   {
      $errmsg = 'Please enter code';
   }

}

But its not working. Only javascript validation is working.PHP validation is not working.

Can any one suggest me????

+1  A: 

As the form action="" is blank, the form is being posted to the same file. You indicated that you have your validation script in another file!

Ankit Jain
A: 

The $errmsg variable you're using is not global. It needs to be global if you intent to use it inside multiple functions.

jmz
A: 

You are checking against 'postcode', but postcode is nowhere set in your form.

TheCandyMan666
There are more fields in the HTML form.For this snippet i have inlcuded few fields alone.Postcode field is there.PHP validation is not workingIf i put validation in javascript , its working
Vithya