Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.56 KB | None | 0 0
  1. setTimeout(function() {
  2. $('body').fadeOut(400, function() {
  3. location.reload();
  4. setTimeout(function() {
  5. $('body').fadeIn(400);
  6. }, 500);
  7. window.scrollTo(x - coord, y - coord);
  8. });
  9. }, 2000);
  10.  
  11. <script type="text/javascript">
  12. jQuery(document).ready(function(){
  13. jQuery("#addlocation").validationEngine();
  14. $("#addlocation").bind("jqv.field.result", function(event, field, errorFound, prompText){ console.log(errorFound) })
  15. });
  16. </script>
  17. <script type="text/javascript">
  18. $(document).ready(function(){
  19. $('#addlocation').submit(function(){
  20.  
  21. //check the form is not currently submitting
  22. if($(this).data('formstatus') !== 'submitting'){
  23.  
  24. //setup variables
  25. var form = $(this),
  26. formData = form.serialize(),
  27. formUrl = form.attr('action'),
  28. formMethod = form.attr('method'),
  29. responseMsg = $('#saverecordresponse');
  30.  
  31. //add status data to form
  32. form.data('formstatus','submitting');
  33.  
  34. //show response message - waiting
  35. responseMsg.hide()
  36. .addClass('response-waiting')
  37. .text('Please Wait...')
  38. .fadeIn(200);
  39.  
  40. //send data to server for validation
  41. $.ajax({
  42. url: formUrl,
  43. type: formMethod,
  44. data: formData,
  45. success:function(data){
  46.  
  47. //setup variables
  48. var responseData = jQuery.parseJSON(data),
  49. klass = '';
  50.  
  51. //response conditional
  52. switch(responseData.status){
  53. case 'error':
  54. klass = 'response-error';
  55. break;
  56. case 'success':
  57. klass = 'response-success';
  58. break;
  59. }
  60.  
  61. //show reponse message
  62. responseMsg.fadeOut(200,function(){
  63. $(this).removeClass('response-waiting')
  64. .addClass(klass)
  65. .text(responseData.message)
  66. .fadeIn(200,function(){
  67. //set timeout to hide response message
  68. setTimeout(function(){
  69. responseMsg.fadeOut(200,function(){
  70. $(this).removeClass(klass);
  71. form.data('formstatus','idle');
  72. });
  73. },3000)
  74. if (klass=='response-success')
  75. {
  76. setTimeout(function () {
  77. $('body').fadeOut(400, function () {
  78. location.reload();
  79. setTimeout(function () {
  80. $('body').fadeIn(400);
  81. }, 500);
  82. window.scrollTo(x - coord, y - coord);
  83. });
  84. }, 2000);
  85. }
  86. });
  87. });
  88. }
  89. });
  90. }
  91.  
  92. //prevent form from submitting
  93. return false;
  94. });
  95. });
  96. </script>
  97.  
  98. <?php
  99.  
  100.  
  101. //sanitize data
  102. $userid = mysql_real_escape_string($_POST['userid']);
  103. $locationname = mysql_real_escape_string($_POST['locationname']);
  104. $returnedaddress = mysql_real_escape_string($_POST['returnedaddress']);
  105.  
  106. if(empty($locationname)){
  107. $status = "error";
  108. $message = "You need to enter a name for this location!";
  109. }
  110.  
  111. else{
  112. $query = mysql_query("INSERT INTO `table` (userid, locationname, returnedaddress) VALUES ('$userid', '$locationname', '$returnedaddress')");
  113. if($query){ //if insert is successful
  114. $status = "success";
  115. $message = "Location Saved!";
  116. }
  117. else { //if insert fails
  118. $status = "error";
  119. $message = "I'm sorry, there has been a technical error!";
  120. }
  121.  
  122. }
  123.  
  124. //return json response
  125. $data = array(
  126. 'status' => $status,
  127. 'message' => $message
  128. );
  129.  
  130. echo json_encode($data);
  131. exit;
  132. ?>
  133.  
  134. if(Yourvalidation!=true)
  135. {
  136. return false;
  137. }
  138.  
  139. //response conditional
  140. switch(responseData.status){
  141. case 'error':
  142. klass = 'response-error';
  143. break;
  144. case 'success':
  145. klass = 'response-success';
  146. break;
  147. }
  148.  
  149. responseMsg.fadeOut(200, function () {
  150. $(this).removeClass('response-waiting')
  151. .addClass(klass)
  152. .text(responseData.message)
  153. .fadeIn(200, function () {
  154. //set timeout to hide response message
  155. setTimeout(function () {
  156. responseMsg.fadeOut(200, function () {
  157. $(this).removeClass(klass);
  158. form.data('formstatus', 'idle');
  159. });
  160. }, 3000)
  161. if (klass=='response-success')
  162. {
  163. setTimeout(function () {
  164. $('body').fadeOut(400, function () {
  165. location.reload();
  166. setTimeout(function () {
  167. $('body').fadeIn(400);
  168. }, 500);
  169. window.scrollTo(x - coord, y - coord);
  170. });
  171. }, 2000);
  172. }
  173. else
  174. {
  175. return false; //use return false in else condition
  176. }
  177. });
  178. });
  179.  
  180. if(Page_ClientValidate())
  181. return true;
  182. else
  183. return false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement