Ver Mensaje Individual
  #3 (permalink)  
Antiguo 20/01/2013, 10:27
Avatar de satjaen
satjaen
 
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 7 meses
Puntos: 10
Respuesta: Pasar variable de php

Cita:
Iniciado por JairLizcano Ver Mensaje
Demasiado lío, valida simplemente los campos desde el cliente con JS y deja que el flujo normal del formulario y su respectivo action te dirijan al documento PHP objetivo.

Puedes hacer algo como esto:

HTML:
Código HTML:
<form action = 'alta_cliente.php' method = 'POST' onsubmit = 'return toValidate();'>
   <input name="telefonos" type="text" id="telefonos" size="9" maxlength="9" />
   <input type = 'submit' value = 'Enviar'/>
</form> 
JS:
Código HTML:
function toValidate() {

   if(data.length=='0'){
      
      var telefonos = document.getElementsByName('telefonos');

      if (confirm("¿Nuevo Cliente?")) { 
      
         return true;        
      } else { 
      
         return false;     
      }
}
Buena suerte.
Gracias JairLizcano, lo he puesto así pero no me hacer el alert ni me lleva a alta_cliente.php:

Código:
<form id="frm_filtro" method="post" action="alta_cliente.php" onsubmit = 'return toValidate();' name="form1">
<input name="telefonos" type="text" id="telefonos" size="9" maxlength="9" />
<button type="button" id="btnfiltrar" name="btnfiltrar" style="cursor:pointer;">
<img src="imagenes_menu/boton_buscar.jpg" width="100%"/>
</button>
Código Javascript:
Ver original
  1. function filtrar()
  2.  
  3. {
  4.  
  5. $.ajax({
  6. data: $("#frm_filtro").serialize()+ordenar,
  7. type: "POST",
  8. dataType: "json",
  9. url: "ajax.php?action=listar",
  10. beforeSend:function(){
  11. $('.carga1').css('display','block');
  12. $('.carga1').html("<img src='imagenes_menu/ajax-loader4.gif' align='center' /><br />Cargando...");
  13.  },
  14.  complete: function() {
  15.  
  16. $(".carga1").show();
  17.  
  18. $(".carga1").hide();
  19.  
  20. },
  21. success: function(data){
  22. var html_user ='' ;
  23.  if(data.length > 0){
  24. $.each(data, function(i,item){
  25. html_user += '<tr ondblclick="pulsar(this, ' + *String.fromCharCode(39) + item.id_aviso + String.fromCharCode(39) *+ ');" >';
  26. html_user += '<td ><input name="demo" type="radio" value="' + item.id_aviso + '"/></td>';
  27. html_user += '<td>'+item.id_aviso+'</td>';
  28. html_user += '<td>'+item.telefonos+'</td>';
  29. html_user += '<td>'+item.name+' '+item.apellidos+'</td>';
  30. html_user += '<td>'+item.localidad+'</td>';
  31. html_user += '</tr>';
  32.  });
  33.  }
  34.  if(html_user == '')
  35.     html_user = '<tr><td colspan="4" align="center">No se encontraron registros..</td></tr>';
  36.  $("#data tbody").html(html_user);
  37.  $('.carga').html('');
  38.     function toValidate() {
  39.  
  40.    if(data.length=='0'){
  41.      
  42.       var telefonos = document.getElementsByName('telefonos');
  43.  
  44.       if (confirm("¿Nuevo Cliente?")) {
  45.      
  46.          return true;
  47.                  
  48.       } else {
  49.      
  50.          return false;    
  51.       }
  52. }
  53.  }
  54.       }
  55.   });
  56.    }