Ver Mensaje Individual
  #5 (permalink)  
Antiguo 24/10/2012, 21:01
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: Recargar página tras envío exitoso de formulario.

vos sabés que la venía probando en firefox y andaba perfecto, pero en los demás browsers no, le di unas vueltas hasta que pude
quedó asi


perfil.php

Código PHP:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <title>titulo</title>
  6. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  7.  
  8. <script type="text/javascript">
  9. //<![CDATA[
  10. function recargar(){
  11. location.reload(true);
  12. }
  13. function mensaje(texto){
  14.     if(texto == 'ok'){
  15. setTimeout('recargar()', 1500);
  16.     }else{
  17. document.getElementById('mensaje').innerHTML = texto;
  18. }
  19. }
  20. //]]>
  21. </script>
  22. </head>
  23. <body>
  24.     <p>
  25.     <?php echo time(); ?>
  26. </p>
  27. <form action="genera.php" target="genera" method="post" id="fperfil">
  28. <p>
  29. <input type="text" value="" name="perfil" /> <input type="submit" value="generar perfil"  onsubmit="this.form.reset();"/>
  30. </p>
  31. </form>
  32. <div id="mensaje">
  33.     <!-- fix -->
  34. </div>
  35. <iframe src="about:blank" name="genera" id="genera" width="0" height="0" frameborder="0"></iframe>
  36. </body>
  37. </html>

genera.php
Código PHP:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <title>titulo</title>
  6. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  7. </head>
  8. <body>
  9. <?php
  10. $datos = $_POST['perfil'];
  11. $crearcvs = file_put_contents("temp.csv",$datos,LOCK_EX);
  12. if($crearcvs !== false){
  13.     ?>
  14. <script type="text/javascript">
  15. //<![CDATA[
  16. /* script */
  17. parent.mensaje('ok');
  18. window.location.href = 'temp.csv';
  19. //]]>
  20. </script>
  21.  
  22. <?php
  23. }else{
  24. ?>
  25.     <script type="text/javascript">
  26. //<![CDATA[
  27. /* script */
  28. parent.mensaje('error');
  29. //]]>
  30. </script>
  31. <?php
  32. }
  33.  
  34. ?>
  35. </body>
  36. </html>

Demo
http://foros.emprear.com/php/perfil/perfil.php

la probé en todos y funciona
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.