Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- setTimeout(function() {
- $('body').fadeOut(400, function() {
- location.reload();
- setTimeout(function() {
- $('body').fadeIn(400);
- }, 500);
- window.scrollTo(x - coord, y - coord);
- });
- }, 2000);
- <script type="text/javascript">
- jQuery(document).ready(function(){
- jQuery("#addlocation").validationEngine();
- $("#addlocation").bind("jqv.field.result", function(event, field, errorFound, prompText){ console.log(errorFound) })
- });
- </script>
- <script type="text/javascript">
- $(document).ready(function(){
- $('#addlocation').submit(function(){
- //check the form is not currently submitting
- if($(this).data('formstatus') !== 'submitting'){
- //setup variables
- var form = $(this),
- formData = form.serialize(),
- formUrl = form.attr('action'),
- formMethod = form.attr('method'),
- responseMsg = $('#saverecordresponse');
- //add status data to form
- form.data('formstatus','submitting');
- //show response message - waiting
- responseMsg.hide()
- .addClass('response-waiting')
- .text('Please Wait...')
- .fadeIn(200);
- //send data to server for validation
- $.ajax({
- url: formUrl,
- type: formMethod,
- data: formData,
- success:function(data){
- //setup variables
- var responseData = jQuery.parseJSON(data),
- klass = '';
- //response conditional
- switch(responseData.status){
- case 'error':
- klass = 'response-error';
- break;
- case 'success':
- klass = 'response-success';
- break;
- }
- //show reponse message
- responseMsg.fadeOut(200,function(){
- $(this).removeClass('response-waiting')
- .addClass(klass)
- .text(responseData.message)
- .fadeIn(200,function(){
- //set timeout to hide response message
- setTimeout(function(){
- responseMsg.fadeOut(200,function(){
- $(this).removeClass(klass);
- form.data('formstatus','idle');
- });
- },3000)
- if (klass=='response-success')
- {
- setTimeout(function () {
- $('body').fadeOut(400, function () {
- location.reload();
- setTimeout(function () {
- $('body').fadeIn(400);
- }, 500);
- window.scrollTo(x - coord, y - coord);
- });
- }, 2000);
- }
- });
- });
- }
- });
- }
- //prevent form from submitting
- return false;
- });
- });
- </script>
- <?php
- //sanitize data
- $userid = mysql_real_escape_string($_POST['userid']);
- $locationname = mysql_real_escape_string($_POST['locationname']);
- $returnedaddress = mysql_real_escape_string($_POST['returnedaddress']);
- if(empty($locationname)){
- $status = "error";
- $message = "You need to enter a name for this location!";
- }
- else{
- $query = mysql_query("INSERT INTO `table` (userid, locationname, returnedaddress) VALUES ('$userid', '$locationname', '$returnedaddress')");
- if($query){ //if insert is successful
- $status = "success";
- $message = "Location Saved!";
- }
- else { //if insert fails
- $status = "error";
- $message = "I'm sorry, there has been a technical error!";
- }
- }
- //return json response
- $data = array(
- 'status' => $status,
- 'message' => $message
- );
- echo json_encode($data);
- exit;
- ?>
- if(Yourvalidation!=true)
- {
- return false;
- }
- //response conditional
- switch(responseData.status){
- case 'error':
- klass = 'response-error';
- break;
- case 'success':
- klass = 'response-success';
- break;
- }
- responseMsg.fadeOut(200, function () {
- $(this).removeClass('response-waiting')
- .addClass(klass)
- .text(responseData.message)
- .fadeIn(200, function () {
- //set timeout to hide response message
- setTimeout(function () {
- responseMsg.fadeOut(200, function () {
- $(this).removeClass(klass);
- form.data('formstatus', 'idle');
- });
- }, 3000)
- if (klass=='response-success')
- {
- setTimeout(function () {
- $('body').fadeOut(400, function () {
- location.reload();
- setTimeout(function () {
- $('body').fadeIn(400);
- }, 500);
- window.scrollTo(x - coord, y - coord);
- });
- }, 2000);
- }
- else
- {
- return false; //use return false in else condition
- }
- });
- });
- if(Page_ClientValidate())
- return true;
- else
- return false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement