Click here to Skip to main content
15,936,565 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
my form validations are not working check once

XML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Valliation</title>
<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $("form.register").change(function() {
        $.post("check.php", $("form.register").serialize(), function( data ) {
            if( data.username == "inuse" )
                $("p#username_error").slideDown();
            else
                $("p#username_error").hide();
            if( data.contact == "nocontact" )
                $("p#contact_error").slideDown();
            else
                $("p#contact_error").hide();
            if( data.email == "notvalid" )
                $("p#email_error").slideDown();
            else
                $("p#email_error").hide();

                if( data.location == "nolocation" )
                $("p#location_error").slideDown();
            else
                $("p#location_error").hide();

                if( data.place == "noplace" )
                $("p#place_error").slideDown();
            else
                $("p#place_error").hide();

                if( data.bhk == "nobhk" )
                $("p#bhk_error").slideDown();
            else
                $("p#bhk_error").hide();

                if( data.brs == "nobrs" )
                $("p#brs_error").slideDown();
            else
                $("p#brs_error").hide();
                if( data.area == "noarea" )
                $("p#area_error").slideDown();
            else
                $("p#area_error").hide();
                if( data.amount == "noamount" )
                $("p#amount_error").slideDown();
            else
                $("p#amount_error").hide();


        }, "json");
    });
});
</script>



</head>

<body>
<form action="register.php" method="post" class="register">
                    <p align="center">POST YOUR PROPERTY HERE</p>
                          <table width="315" border="0" cellspacing="1" cellpadding="7">

                      <tr>

                        <th scope="row">For:</th>
                        <td><select name="type">
                        <option value="sale">Sale</option>
                            <option value="rent">Rent</option>
                            <option value="share">Share</option>
                            </td>
                      </tr>

                      <tr>

                        <th scope="row">Name:</th>

                        <td>
                        <input type="text" name="username" id="txtname" />
                            <p id="username_error" class="error">That Username is unavailable</p>
                            </td>

                      </tr>

                      <tr>
                        <th scope="row">Contact:</th>
                        <td>
                        <input type="text" name="contact"  />
                            <p id="contact_error" class="error">Contact Number is unavailable</p>
                            </td>
                      </tr>

                      <tr>

                        <th scope="row">Email:</th>
                        <td><input type="text" name="email"  />
                            <p id="email_error" class="error">Email is not valid</p><br/>
                            </td>
                      </tr>

                      <tr>
                        <th scope="row">Property: </th>
                        <td>
                        <select name="property"><option value="Buildings">Buildings</option>
                            <option value="site">Site</option>
                            <option value="land">Land</option></td>
                      </tr>
                      <tr>
                        <th scope="row">Property Type:</th>
                    <td>
                    <select name="ptype"><option value="Residencial">Residencial</option>
                            <option value="commercial">Commercial</option>
                            <option value="apartments">Apartments</option>
                            </td>
                      </tr>
                      <tr>
                        <th scope="row">Location:
                    </th>

                        <td>
                        <input type="text" name="location"  />
                            <p id="location_error" class="error">Location is unavailable</p>
                            </td>
                      </tr>
                      <tr>

                        <th scope="row">Place:
                        </th>
                        <td>
                        <input type="text" name="place"  />
                            <p id="place_error" class="error">Place is unavailable</p>
                            </td>

                      </tr>

                      <tr>

                        <th scope="row">BHK:
                        </th>
                        <td>
                        <input type="text" name="bhk"  />
                            <p id="bhk_error" class="error">BHK is unavailable</p>
                            </td>

                      </tr>

                      <tr>

                        <th scope="row">Bathrooms:
                        </th>
                        <td>
                        <input type="text" name="brs"  />
                            <p id="brs_error" class="error">Enter Bathrooms number</p>
                            </td>
                      </tr>

                      <tr>

                        <th scope="row">Area:
                        </th>
                        <td>
                        <input type="text" name="area"  />
                            <p id="area_error" class="error">Area is unavailable</p>
                            </td>

                      </tr>
                      <tr>

                        <th scope="row">Amount:
                        </th>
                        <td>
                        <input type="text" name="amount"  />
                            <p id="amount_error" class="error">Amount is unavailable</p>
                            </td>

                      </tr>
                      <tr>

                        <th scope="row">&nbsp;<input type="submit" name="submit" value="register" onsubmit="return validateUsername()";>
                        </th>
                        <td>
                        <input type="file" name="file" /></tr>
                                                 <tr>
                                                 <th scope="row">&nbsp;</th>
                             </tr>

</form>
                    </table>
</body>
</html>




and my check.php is


PHP
<?php
$data = array( "username" => "", "contact" => "", "email" => "", "location" => "", "place" => "", "bhk" => "", "brs" => "", "area" => "", "amount" => "" );
if( isset($_POST["username"]) ) {
    if( in_array( $_POST["username"],  $usernames) ) {
        $data["username"] = "inuse";
    }
}
if( isset($_POST["contact"])  ) {
    if( $_POST["contact"] != "" && is_numeric($_POST["contact"] ) {
        $data["contact"] = "no contact";
    }
}
if( isset( $_POST["email"] ) ) {
    if( $_POST["email"] != "" && !preg_match( "/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST["email"] ) ) {
        $data["email"] = "notvalid";
    }
}
if( isset($_POST["location"])  ) {
    if( $_POST["location"]!= "" ) {
        $data["location"] = "nolocation";
    }
}
if( isset($_POST["place"])  ) {
    if( $_POST["place"] != "" ) {
        $data["place"] = "noplace";
    }
}
if( isset($_POST["bhk"])  ) {
    if( $_POST["bhk"] != "" && is_numeric($_POST["bhk"] ) {
        $data["bhk"] = "nobhk";
    }
}
if( isset($_POST["brs"])  ) {
    if( $_POST["brs"] != "" && is_numeric($_POST["brs"] ) {
        $data["brs"] = "nobrs";
    }
}
if( isset($_POST["area"])  ) {
    if( $_POST["area"] != "" && is_numeric($_POST["area"] ) {
        $data["area"] = "noarea";
    }
}if( isset($_POST["amount"])  ) {
    if( $_POST["amount"] != "" && is_numeric($_POST["amount"] ) {
        $data["amount"] = "noamount";
    }
}
echo json_encode( $data );
        mysql_close($con);
?>
Posted
Comments
ridoy 27-Aug-12 3:22am    
too much code to examine..u need to tell on which point your code not working or what error you get?
AmitGajjar 27-Aug-12 4:36am    
try to implement your validation for one field and use jQuery examples to use it. try to diagnose your issue.
Manjula.g 27-Aug-12 8:18am    
Ya it is working now,
thanks for your time

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900