Armando una clase para crear formularios me plateé diferentes formas de agregar propiedades al tag <form>.
¿Cuál creen que es la mejor opción? Proponen otra?
Código PHP:
<?php
class Form {
private $action = NULL;
private $method = "POST";
private $enctype = NULL;
//private $input_type = array();
//private $input_name;
public function __construct() {
$this->action;
$this->method;
$this->enctype;
}
/*
* FORMA 1
*/
public function set_form($accion = NULL, $encode = NULL, $metodo = "POST") {
$this->action = $accion;
$this->enctype = $encode;
$this->method = $metodo;
}
public function get_form() {
return '<form action="'. $this->action .'" method="'. $this->method .'" enctype="'. $this->enctype .'">';
}
/*
* FORMA 2
*/
public function create($accion = NULL, $encode = NULL, $metodo = "POST") {
return '<form action="'. $this->action = $accion .'" method="'. $this->method = $metodo .'" enctype="'. $this->enctype = $encode .'">';
}
/*
* FORMA 3
*/
protected function read($params = array()) {
$reading = false;
foreach ($params as $property => $value) {
//$reading .= " " . $property . "=" . '"' . $value .'"';
$reading .= " ";
$reading .= "$property";
$reading .= "=";
$reading .= '"' .$value . '"';
}
return $reading;
}
public function formCreate($attrs = array()) {
$form = '<form'. $this->read($attrs) .'>';
return $form;
}
/*
* FORMA 4 ¿?
*/
}
?>