Ver Mensaje Individual
  #2 (permalink)  
Antiguo 01/11/2012, 06:32
Avatar de djaevi
djaevi
 
Fecha de Ingreso: marzo-2007
Ubicación: Moreno, Buenos Aires
Mensajes: 400
Antigüedad: 17 años
Puntos: 47
Respuesta: cambiar la propiedad action de un form con php?

Si imprimes tu codigo html del formulario con php claro que puedes hacerlo:

Código PHP:
Ver original
  1. $texto = "";
  2. $texto .= "<form id='miFormulario' method='post' ";
  3.  
  4. if ($especialista == "mecanico") {
  5.     $texto .= "action='mecanico.php'>";
  6. }else{
  7.     $texto .= "action='doctor.php'>";
  8. }
  9.  
  10. $texto .= "<input type='text' name='nombreyapellido'><br>";
  11. $texto .= "<input type='text' name='telefono'><br>";
  12. $texto .= "<input type='text' name='email'><br><br>";
  13. $texto .= "<input type='submit' value='Enviar'>";
  14.  
  15. echo $texto;

Si lo quisieras hacer en tiempo real por ejemplo presionando un boton deberias usar javascript:

Código Javascript:
Ver original
  1. function cambiarAccion(url) {
  2. document.getElementById("miFormulario").action = url;
  3. }

Código HTML:
Ver original
  1. <form id='miFormulario' method='post' action=''>;
  2.  
  3. <input type='text' name='nombreyapellido'><br>
  4. <input type='text' name='telefono'><br>
  5. <input type='text' name='email'><br><br>
  6. <input type='submit' value='Enviar'>
  7.  
  8. </form>
  9.  
  10. <input type="button" value="Mecanico" onclick="cambiarAccion('mecanico.php')">
  11. <input type="button" value="Doctor" onclick="cambiarAccion('doctor.php')">

Probalo y me comentas como te fue ;) Salu2

Última edición por djaevi; 01/11/2012 a las 06:37