Skip to main content

Jquery form validation with ajax request

Include library


<script src="js/jquery.min.js"></script> <script src="js/jquery.validate.js"></script>


<?php$_SESSION['code']=rand(1000,2000);?> 



<form name="form-signup" id="form-signup" method="post" > <table width="50%"> <tr> <td>Name</td> <td><input type="text" name="name" id="name" class="change"></td> </tr> <tr> <td>Email</td> <td><input type="text" name="email" id="email" class="change"></td> </tr> <tr> <td>Username</td> <td><input type="text" name="username" id="username" class="change"></td> </tr> <tr> <td>Password</td> <td><input type="text" name="password" id="password"class="change"></td> </tr> <tr> <td>Re-Password</td> <td><input type="text" name="con_password" id="con_password" class="change"></td> </tr> <tr> <td>Code</td> <td><?php echo $_SESSION['code'];?><input type="text" name="code" id="code" ></td> </tr> <tr> <td>&nbsp;</td> <td><input type="submit" name="submit" id="submit" value="Sign Up"></td> </tr> </table> </form>


<script type="application/javascript" language="javascript"> jQuery("#form-signup").validate( { errorElement:'div', rules:{ name:{ required: true }, email:{ required: true, email:true, remote:'include/ajax_check_user.php' }, username:{ required: true, remote:'include/ajax_check_user.php' }, password:{ required: true, minlength:8, maxlength:14 }, con_password:{ equalTo:"#password" }, code:{ required: true, remote:'include/ajax_check_user.php' } }, submitHandler: function (form) { jQuery.ajax({ type: "POST", url: "include/ajax_login.php?registration=1", data: jQuery(form).serialize(), success: function () { } }); return false; // required to block normal submit since you used ajax } }); </script>

ajax_check_user.php

<?php include('class.crud.php'); $result = 'true'; if(trim(@$_GET['username'])!= "") { $order = "SELECT user_id FROM tbl_user where user_id='".trim($_GET['username'])."'"; $result_rel = mysql_query($order); $row = @mysql_num_rows($result_rel); if($row=='1') { $result='false'; } } if(trim(@$_GET['email'])!= "") { $order = "SELECT email FROM tbl_user where email='".trim($_GET['email'])."'"; $result_rel = mysql_query($order); $row = @mysql_num_rows($result_rel); if($row=='1') { $result='false'; } } if(trim(@$_GET['code'])!= "") { if($_SESSION['code']!=$_GET['code']) { $result='false'; } } echo $result; ?>
ajax_login.php

<?php include('class.crud.php'); if(@$_GET['registration']==1) { print_r($_POST); } ?>






Comments

Post a Comment

Popular posts from this blog

Select Insert Update Delete With Image In Php MySQL

        CRUD with image upload is a very common task in web development ( CRUD stands for Create/Read/Update/Delete ). The main purpose of a CRUD is that enables user’s create/read/update/delete data using PHP & MYSQL. Table of Content Create Database Insert Record with image upload Show Record Edit Record Delete Record     

PHP+AJAX+MYSQL: Sort & Save using Drag & Drop (TABLE TR)

" Drag, Drop, Sort, Save "  Drag & Drop : Move the draggable element by clicking on it with the mouse and dragging it anywhere within the viewport. Sor t: The sort order can be either alphabetic or numeric, and either ascending or descending.       Here we had created demo that allow the user to drag and drop elements and quickly  and save them with PHP + MySQL+ AJAX +JQUERY on the server side. Table of content 1) Drag and drop element on every click 2) Sort data on the server side using PHP+MYSQL 3) Great user interface and  easy to execute with a few lines of code