Guest User

Untitled

a guest
Jan 22nd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.07 KB | None | 0 0
  1. localhost/wizard/saveTemp.php?step=6
  2.  
  3. <a href="#" class="back">Atras</a>
  4. <a href="#" class="next">Continuar</a>
  5.  
  6. <a href="#" class="next" onclick="show_step('4')>Continuar</a>
  7.  
  8. <?php include 'php/wizard.php' ?>
  9. <!DOCTYPE html>
  10. <html>
  11. <head>
  12. <title></title>
  13. <script src="assets/js/jquery.min.js"></script>
  14.  
  15. <script type="text/javascript">
  16.  
  17. var currentStep = <?php echo $step ?>; // Variable que indica el paso actual
  18. var radio = <?php echo $radio ?>; //Valor del radio seleeccionado
  19.  
  20. function show_step(step) {
  21. var data = $("#form").serialize();
  22. var url = 'saveTemp.php?step=' + step;
  23. var valid = true;
  24.  
  25. // [OPCIONAL] Validamos solo si se esta yendo hacia adelante
  26. if (currentStep < step) {
  27.  
  28. // Buscamos todos los campos dentro del paso actual.
  29. $('#step' + currentStep).find('input').each((idx, el) => {
  30. $field = $(el);
  31.  
  32. // Si el campo esta vacio
  33. if (!$field.val()) {
  34. $field.parent().addClass('error');
  35. valid = false;
  36. } else {
  37. $field.parent().removeClass('error');
  38. }
  39. });
  40. }
  41.  
  42. // Si al menos un campo no fue completado
  43. if (!valid) {
  44. return;
  45. }
  46.  
  47. $.ajax({
  48. type: "POST",
  49. url: url,
  50. data: data
  51. }).done(function(resp){
  52.  
  53. step = parseInt(step);
  54. $('#address').val(resp.address);
  55. $('#email').val(resp.email);
  56. $('#name').val(resp.name);
  57. $('#phone').val(resp.phone);
  58. $('#radio').val(resp.radio);
  59. $('#username').val(resp.username);
  60.  
  61.  
  62. if (step === 2) {
  63. var radio = parseInt(resp.radio);
  64. switch(radio) {
  65. case 1:
  66. urlform = './php/templates/formBanc.php'
  67. break;
  68. case 2:
  69. urlform = './php/templates/formPaypal.php'
  70. break;
  71. case 3:
  72. urlform = './php/templates/formCreditCar.php'
  73. break;
  74. default:
  75. urlform = './php/templates/formError.php'
  76. break;
  77.  
  78. }
  79.  
  80. $('#divPago').load(urlform,function(responseTxt, statusTxt, xhr){
  81.  
  82. if(statusTxt === "success") {
  83. $('.step').css( "display", "none" );
  84. $('#step'+ step).fadeIn("slow");
  85. animacion(step);
  86. }
  87.  
  88. if(statusTxt === "error"){
  89. //
  90. }
  91.  
  92. });
  93.  
  94. } else {
  95. $('.step').css( "display", "none" );
  96. $('#step'+ step).fadeIn("slow");
  97. animacion(step);
  98. }
  99. });
  100.  
  101. $('#step' + currentStep).css("display", "none");
  102. $('#step' + step).fadeIn("slow");
  103. currentStep = step;
  104.  
  105. };
  106.  
  107. $(function() {
  108. $('#step' + currentStep).fadeIn("slow");
  109.  
  110. $('a.next').click(e => {
  111. e.preventDefault();
  112. show_step(currentStep + 1);
  113. });
  114.  
  115. $('a.back').click(e => {
  116. e.preventDefault();
  117. show_step(currentStep - 1);
  118. });
  119.  
  120.  
  121.  
  122. });
  123. </script>
  124.  
  125. <style type="text/css">
  126. label {
  127. display: block;
  128. }
  129. .step {
  130. display: none;
  131. }
  132. .errorMsg {
  133. display: none;
  134. color: red;
  135. }
  136. .error .errorMsg {
  137. display: block;
  138. }
  139. </style>
  140. </head>
  141. <body>
  142. <form id="form">
  143. <div id="step1" class="step">
  144. <h1>Paso 1</h1>
  145. <!-- Diferentes tipos de campo input u otros que se necesitan validar-->
  146. <label>
  147. <span>Nombre :</span>
  148. <input name="nombre" />
  149. <div class="errorMsg">Debe ingresar su nombre</div>
  150. </label>
  151. <label>
  152. <span>Apellido :</span>
  153. <input name="apellido" />
  154. <div class="errorMsg">Debe ingresar su apellido</div>
  155. </label>
  156. <!-- &&& -->
  157. <!--<a href="#" onclick="show_step('2')">continuar</a>-->
  158. <a href="" class="next">Continuar</a>
  159. </div>
  160. <div id="step2" class="step">
  161. <h1>Paso 2</h1>
  162. <!-- Diferentes tipos de campo input u otros que se necesitan validar-->
  163. <label>
  164. <span>Email :</span>
  165. <input name="email" />
  166. <div class="errorMsg">Debe ingresar su email</div>
  167. </label>
  168. <!-- &&& -->
  169. <a href="" class="back">Atras</a>
  170. <a href="" class="next">Continuar</a>
  171. <!--<a href="#" onclick="show_step('1')">Atras</a>
  172. <a href="#" onclick="show_step('3')">continuar</a>-->
  173. </div>
  174. <div id="step3" class="step">
  175. <h1>Paso 3</h1>
  176. <!-- Diferentes tipos de campo input u otros que se necesitan validar-->
  177. <a href="" class="back">Atras</a>
  178. <a href="" class="next">Continuar</a>
  179. <!--<a href="#" onclick="show_step('2')">Atras</a>
  180. <a href="#" onclick="show_step('4')">continuar</a>-->
  181. </div>
  182. <div id="step4" class="step">
  183. <h1>Paso 4</h1>
  184. <!-- Diferentes tipos de campo input u otros que se necesitan validar-->
  185. <a href="" class="back">Atras</a>
  186. <a href="" class="next">Continuar</a>
  187. <!--<a href="#" onclick="show_step('3')">Atras</a>-->
  188. </div>
  189. </form>
  190. </body>
  191. </html>
  192.  
  193. <?php
  194. session_start();
  195.  
  196. $step = isset($_GET['step']) ? $_GET['step'] : 1;
  197.  
  198. // Guardamos los datos del formulario en una variable de session
  199. $_SESSION['datos_form'] = $_POST;
  200. // añadimos tambien al array el paso, no se puede utilizar este nombre (__paso__) como name en el formulario
  201.  
  202.  
  203. include 'php/validate.php';
  204.  
  205. header('Content-Type: application/json');
  206.  
  207. $json = array(
  208.  
  209. 'radio' => $radio,
  210. 'step' => $step,
  211. 'name' => $name,
  212. 'email' => $email,
  213. 'phone' => $phone,
  214. 'address' => $address,
  215. 'username' => $username
  216. );
  217.  
  218. echo json_encode($json);
  219.  
  220. <?php
  221. // Iniciamos la sessión
  222. session_start();
  223. if (isset($_GET['p'])) {
  224. session_destroy();
  225. session_start();
  226. }
  227.  
  228.  
  229. include 'validate.php';
  230.  
  231. $r =array(
  232. 1 => 'Transferencia Bancaria',
  233. 2 => 'PayPal',
  234. 3 => 'Tarjeta de credito',
  235. );
  236.  
  237. <?php
  238.  
  239. $datosForm = (isset($_SESSION['datos_form']) && is_array($_SESSION['datos_form'])) ? $_SESSION['datos_form'] :array();
  240.  
  241. $sPaso = isset($datosForm['__step__']) ? $datosForm['__step__'] : 1;
  242. $step = isset($step) ? $step : $sPaso;
  243.  
  244. $name = isset($datosForm['name']) ? $datosForm['name']: '';
  245. $email = isset($datosForm['email']) ? $datosForm['email']: '';
  246. $phone = isset($datosForm['phone']) ? $datosForm['phone']: '';
  247. $address = isset($datosForm['address']) ? $datosForm['address']: '';
  248. $username = isset($datosForm['username']) ? $datosForm['username']: '';
  249. $password = isset($datosForm['password']) ? $datosForm['password']: '';
  250.  
  251. $radio = isset($datosForm['radio']) ? $datosForm['radio'] : 1;
  252.  
  253. $_SESSION['datos_form']['__step__'] = $step;
Add Comment
Please, Sign In to add comment