Clase para crear formularios – FormBox 0.1
Jueves, 21. Enero 2010
Jodiendo un rato con poo en php codee una simple clase
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | <?php class form { private $action; private $method; private $size; private $maxlength; private $id; private $src; private $elements; private $name; private $value; private $text; public function __construct($action, $method) { $this->action = $action; $this->method = $method; } public function openform() { echo "<form action=\"" . $this->action . "\" method=\"" . $this->method . "\"> \n"; } public function field_text($id, $size, $maxlength) { $this->id = $id; $this->size = $size; $this->maxlength = $maxlength; echo "<input type=\"text\" id=\"" . $this->id . "\" size=\"" . $this->size . "\" maxlength=\"" . $this->maxlength . "\"> \n"; } public function field_password($id, $size, $maxlength) { $this->id = $id; $this->size = $size; $this->maxlength = $maxlength; echo "<input type=\"password\" id=\"" . $this->id . "\" size=\"" . $this->size . "\" maxlength=\"" . $this->maxlength . "\"> \n"; } public function select($elements = array(), $name) { $this->name = $name; $this->elements = $elements; echo "<select name=\"" . $this->name . "\"> \n"; foreach ($this->elements as $single) { echo "<option name=\"" . $single . "\" value=\"" . $single . "\">" . $single . "</option> \n"; } echo "</select>"; } public function field_image($src) { $this->src = $src; echo "<input type=\"image\" src=\"" . $this->src . "\">"; } public function field_button($name, $value) { $this->name = $name; $this->value = $value; echo "<input type=\"button\" name=\"" . $this->name . "\" value=\"" . $this-> value . "\"> \n"; } public function checkbox($name, $value, $text) { $this->name = $name; $this->value = $value; $this->text = $text; echo "<lebel><input type=\"checkbox\" name=\"" . $this->name . "\" value=\"" . $this-> value . "\"> " . $this->text . "</label> \n"; } public function closeform() { echo "</form> \n"; } } ?> |