Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.63 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <?php
  3. function DB($a) { echo '<pre>'; var_dump($a); echo '</pre>'; }
  4. class Form
  5. {
  6.        function __construct($id='form',$method='POST',$action='') {
  7.                $this->method = $method;
  8.                $this->action = $action;
  9.                $this->id = $id;
  10.                $this->formulario = '<form action="'.$this->action.'" enctype="application/x-www-form-urlencoded" method="'.$this->method.'" id="'.$this->id."\" accept-charset=\"utf-8\">\n";
  11.        }
  12.  
  13.        public function BR($cant=1) {
  14.                for($i=0;$i<$cant;$i++) $this->formulario .= "<br />";
  15.        }
  16.  
  17.        public function Input($datos) {
  18.                for($i=0;$i<count($datos);$i++)
  19.                {
  20.                        if($datos[$i]['tipo'] == 'file') $this->formulario = str_replace('application/x-www-form-urlencoded', 'multipart/form-data', $this->formulario);
  21.                        $this->formulario .= '<label for="'.$datos[$i]['id'].'">'.ucfirst($datos[$i]['nombre'])."</label>\n";
  22.                        $this->formulario .= '<input type="'.$datos[$i]['tipo'].'" name="'.$datos[$i]['nombre'].'" id="'.$datos[$i]['id']."\" /><br />\n";
  23.                }
  24.        }
  25.  
  26.        public function Enviar($enviar,$br=0) {
  27.                for($i=0;$i<count($enviar);$i++)
  28.                {
  29.                        $this->formulario .= '<input type="'.$enviar[$i]['tipo'].'" name="'.$enviar[$i]['nombre'].'" value="'.$enviar[$i]['value']."\" />\n";
  30.                        $this->formulario .= ($br)?'<br />':'';
  31.                }
  32.        }
  33.  
  34.        public function Generar() {
  35.                $this->formulario .= '</form>';
  36.                return $this->formulario;
  37.        }
  38.  
  39. }
  40.  
  41. $datos = array();
  42. $datos[0]['tipo'] = 'user';         $datos[0]['nombre'] = 'usuario';        $datos[0]['id'] = 'usuario';
  43. $datos[1]['tipo'] = 'password';     $datos[1]['nombre'] = 'password';       $datos[1]['id'] = 'password';
  44. $datos[2]['tipo'] = 'text';         $datos[2]['nombre'] = 'sistema';        $datos[2]['id'] = 'sistema';
  45. $datos[3]['tipo'] = 'text';         $datos[3]['nombre'] = 'subdominio';     $datos[3]['id'] = 'subdominio';
  46. $datos[4]['tipo'] = 'text';         $datos[4]['nombre'] = 'sistema';        $datos[4]['id'] = 'sistema';
  47. $datos[5]['tipo'] = 'file';         $datos[5]['nombre'] = 'FICHERO';        $datos[5]['id'] = 'FICHERO';
  48.  
  49. $enviar = array();
  50. $enviar[0]['tipo'] = 'submit';      $enviar[0]['nombre'] = 'enviar';        $enviar[0]['value'] = 'Enviar registro';
  51. $enviar[1]['tipo'] = 'reset';       $enviar[1]['nombre'] = 'reset';         $enviar[1]['value'] = 'Resetear Formularo';
  52.  
  53.  
  54. //DB($datos);
  55. $form = new Form('a_cliente');
  56. $form->Input($datos);
  57. $form->Enviar($enviar);
  58. echo $form->Generar();
  59.  
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement