Ver Mensaje Individual
  #3 (permalink)  
Antiguo 11/04/2017, 03:51
Avatar de manuparquegiralda
manuparquegiralda
 
Fecha de Ingreso: junio-2012
Ubicación: Barcelona
Mensajes: 241
Antigüedad: 11 años, 9 meses
Puntos: 39
Respuesta: Codigo de redireccion falla en formulario buscar

Puedes hacerlo con javascript:

Código HTML:
Ver original
  1. <form id="formSearch" action="<?php echo $url; ?>/buscar/" method="GET" class="navbar-form navbar-left" role="search">
  2.     <div class="input-group">
  3.         <input type="text" class="form-control" placeholder="buscador" name="q" id="q" size="60">
  4.         <div class="input-group-btn">
  5.             <button class="btn btn-default" type="submit" ><i class="glyphicon glyphicon-search"></i></button>
  6.         </div>
  7.     </div>
  8. </form>

Código Javascript:
Ver original
  1. (function() {
  2.  
  3.     // Obtenemos el formulario y ponemos a la escucha el evento submit
  4.  
  5.     const form = document.getElementById( "formSearch" );
  6.     form.addEventListener( "submit", ev => submitFormSearhc( ev ));
  7.  
  8.     // Función que se ejecuta al hacer submit en el formulario
  9.  
  10.     function submitFormSearhc( ev ) {
  11.         // Detenemos el envío del formulario
  12.  
  13.         ev.preventDefault();
  14.  
  15.         // Obtenemos el input de búsqueda y la URL del action
  16.  
  17.         const input = document.getElementById( "q" );
  18.         var url = form.attributes.action.value;
  19.  
  20.         // Si hay algún valor, redireccionamos a la URL más el valor del input
  21.  
  22.         if ( input.value ) {
  23.             window.location = url + "" + input.value + "/";
  24.         }
  25.     }
  26.  
  27. })();

Algo así debería de funcionarte
__________________
Diseño Web - Arisman Web

Última edición por manuparquegiralda; 11/04/2017 a las 03:56