Ver Mensaje Individual
  #7 (permalink)  
Antiguo 16/03/2014, 17:20
Avatar de xXn
xXn
 
Fecha de Ingreso: abril-2013
Ubicación: Buenos Aires
Mensajes: 41
Antigüedad: 11 años
Puntos: 2
Respuesta: Cómo crear input desde PHP

Código PHP:
Ver original
  1. <?php
  2.  
  3. require_once("form.class.php");
  4.  
  5. $form = new Form();
  6. $form->iniciarForm("accion" , "post");
  7. $form->agregarCampo("Nombre","text");
  8. $form->agregarCampo("Apellido","text");
  9. $form->agregarCampo("DNI","text");
  10. $form->agregarCampo("Telefono","text");
  11. $form->agregarCampo("enviar","submit", "enviar");
  12. $form->terminarForm();
  13.  
  14. ?>

Código PHP:
Ver original
  1. <?php
  2.  
  3.  
  4. class Form{
  5.      
  6.     public function iniciarForm($accion, $metodo){
  7.         print "<form action='" . $accion ."' method='" . $metodo . "' >";
  8.     }
  9.      
  10.     public function agregarCampo($nombre, $tipo , $valor = null){
  11.         print "<label>" . $nombre . "</label><input type='". $tipo ."' id='" . $nombre . "' value='" . $valor . "' />";
  12.     }
  13.      
  14.     public function terminarForm(){
  15.         print "</form>";
  16.     }
  17.  
  18. }
  19. ?>

Te hice algo muy sencillo orientado a objetos... es algo simple y facil, hay mil formas de mejorarlo pero eso ya te lo dejo a vos.