Guest User

Untitled

a guest
Jan 18th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.91 KB | None | 0 0
  1. <form id="form">
  2. <div id="step1" class="step">
  3. <h1>Paso 1</h1>
  4. <!-- Diferentes tipos de campo input u otros que se necesitan validar-->
  5. <a href="#" onclick="show_step('2')">continuar</a>
  6. </div>
  7. <div id="step2" class="step">
  8. <h1>Paso 2</h1>
  9. <!-- Diferentes tipos de campo input u otros que se necesitan validar-->
  10. <a href="#" onclick="show_step('1')">Atras</a>
  11. <a href="#" onclick="show_step('3')">continuar</a>
  12. </div>
  13. <div id="step3" class="step">
  14. <h1>Paso 3</h1>
  15. <!-- Diferentes tipos de campo input u otros que se necesitan validar-->
  16. <a href="#" onclick="show_step('2')">Atras</a>
  17. <a href="#" onclick="show_step('4')">continuar</a>
  18. </div>
  19. <div id="step4" class="step">
  20. <h1>Paso 4</h1>
  21. <!-- Diferentes tipos de campo input u otros que se necesitan validar-->
  22. <a href="#" onclick="show_step('3')">Atras</a>
  23. <input><-- Finalizar
  24. </div>
  25. </form>
  26.  
  27. function show_step(step){
  28. var data = $( "#form" ).serialize();
  29. var url = 'saveTemp.php?step=' + step;
  30. // recuperamos el lavel del radio button seleccionado
  31. //var valor_radio = $('input:radio[name=radio]:checked').next("label").text();
  32. $.ajax({
  33. type: "POST",
  34. url: url,
  35. data: data
  36. }).done(function(resp){
  37.  
  38. step = parseInt(step);
  39. $('#address').val(resp.address);
  40. $('#email').val(resp.email);
  41. $('#name').val(resp.name);
  42. $('#phone').val(resp.phone);
  43. $('#radio').val(resp.radio);
  44. $('#username').val(resp.username);
  45.  
  46. if (step === 2) {
  47. var radio = parseInt(resp.radio);
  48. switch(radio) {
  49. case 1:
  50. urlform = './app/themes/pay_paypal.php'
  51. break;
  52. case 2:
  53. urlform = './app/themes/pay_paypal2.php'
  54. break;
  55. case 3:
  56. urlform = './app/themes/pay_paypal3.php'
  57. break;
  58. default:
  59. urlform = './app/themes/pay_paypal4.php'
  60. break;
  61.  
  62. }
  63. $('#divPago').load(urlform,function(responseTxt, statusTxt, xhr){
  64. if(statusTxt === "success") {
  65. $('.step').css( "display", "none" );
  66. $('#step'+ step).fadeIn("slow");
  67. animacion(step);
  68. }
  69. if(statusTxt === "error") {
  70. //
  71. }
  72.  
  73. });
  74. } else {
  75. $('.step').css( "display", "none" );
  76. $('#step'+ step).fadeIn("slow");
  77. animacion(step);
  78. }
  79.  
  80. });
  81.  
  82. };
  83.  
  84. $(function() {
  85. show_step(step);
  86. });
  87.  
  88. $("input").each(function () { //inicia un bucle con todos los inputs
  89. if ($(this).val() == '') { //Si el input esta "vacio"
  90. alert("Debe llenar todos los campos");
  91. return false; //detiene el bucle
  92. }
  93. });
  94.  
  95. $("input:checkbox") //solo los checkbox
  96. $("input:radio") //solo los radios
  97. $("select") // los select
  98. //tambien puedes comprobar varios tipos a la vez
  99. $("select, input:text, input:checkbox")
  100.  
  101. if (!$(this).is(':checked')) { //Si el checkbox no esta seleccionado
  102. alert("Debe llenar todos los campos");
  103. return false; //detiene el bucle
  104. });
  105.  
  106. function show_step(step){
  107. var data = $( "#form" ).serialize();
  108. var url = 'saveTemp.php?step=' + step;
  109. var emptyInput = false;
  110.  
  111. $("input").each(function () { //inicia un bucle con todos los inputs
  112. if ($(this).val() == '') { //Si el input esta "vacio"
  113. emptyInput = true;
  114. return false; //detiene el bucle
  115. }
  116. });
  117.  
  118. if (emptyInput) {
  119. alert("Todos los campos son obligatorios");
  120. return void; //Detiene la ejecucion de esta funcion
  121. }
  122. // recuperamos el lavel del radio button seleccionado
  123. //var valor_radio = $('input:radio[name=radio]:checked').next("label").text();
  124. $.ajax({
  125. type: "POST",
  126. url: url,
  127. data: data
  128. }).done(function(resp){
  129.  
  130. step = parseInt(step);
  131. $('#address').val(resp.address);
  132. $('#email').val(resp.email);
  133. $('#name').val(resp.name);
  134. $('#phone').val(resp.phone);
  135. $('#radio').val(resp.radio);
  136. $('#username').val(resp.username);
  137.  
  138. if (step === 2) {
  139. var radio = parseInt(resp.radio);
  140. switch(radio) {
  141. case 1:
  142. urlform = './app/themes/pay_paypal.php'
  143. break;
  144. case 2:
  145. urlform = './app/themes/pay_paypal2.php'
  146. break;
  147. case 3:
  148. urlform = './app/themes/pay_paypal3.php'
  149. break;
  150. default:
  151. urlform = './app/themes/pay_paypal4.php'
  152. break;
  153.  
  154. }
  155. $('#divPago').load(urlform,function(responseTxt, statusTxt, xhr){
  156. if(statusTxt === "success") {
  157. $('.step').css( "display", "none" );
  158. $('#step'+ step).fadeIn("slow");
  159. animacion(step);
  160. }
  161. if(statusTxt === "error") {
  162. //
  163. }
  164.  
  165. });
  166. } else {
  167. $('.step').css( "display", "none" );
  168. $('#step'+ step).fadeIn("slow");
  169. animacion(step);
  170. }
  171. });
  172. };
Add Comment
Please, Sign In to add comment