Remover elección de Taller para Encargados de Taller. Parche 1.
[CLab.git] / include / form.php
blobd16469825bedd944273166c70148953ad5249bb7
1 <?
2 /**
3 * Form.php
5 * The Form class is meant to simplify the task of keeping
6 * track of errors in user submitted forms and the form
7 * field values that were entered correctly.
9 * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
10 * Last Updated: August 19, 2004
13 class Form
15 var $values = array(); //Holds submitted form field values
16 var $errors = array(); //Holds submitted form error messages
17 var $num_errors; //The number of errors in submitted form
19 /* Class constructor */
20 function Form(){
21 /**
22 * Get form value and error arrays, used when there
23 * is an error with a user-submitted form.
25 if(isset($_SESSION['value_array']) && isset($_SESSION['error_array'])){
26 $this->values = $_SESSION['value_array'];
27 $this->errors = $_SESSION['error_array'];
28 $this->num_errors = count($this->errors);
30 unset($_SESSION['value_array']);
31 unset($_SESSION['error_array']);
33 else{
34 $this->num_errors = 0;
38 /**
39 * setValue - Records the value typed into the given
40 * form field by the user.
42 function setValue($field, $value){
43 $this->values[$field] = $value;
46 /**
47 * setError - Records new form error given the form
48 * field name and the error message attached to it.
50 function setError($field, $errmsg){
51 $this->errors[$field] = $errmsg;
52 $this->num_errors = count($this->errors);
55 /**
56 * value - Returns the value attached to the given
57 * field, if none exists, the empty string is returned.
59 function value($field){
60 if(array_key_exists($field,$this->values)){
61 return htmlspecialchars(stripslashes($this->values[$field]));
62 }else{
63 return "";
67 /**
68 * error - Returns the error message attached to the
69 * given field, if none exists, the empty string is returned.
71 function error($field){
72 if(array_key_exists($field,$this->errors)){
73 return "<font size=\"2\" color=\"#ff0000\">".$this->errors[$field]."</font>";
74 }else{
75 return "";
79 /* getErrorArray - Returns the array of error messages */
80 function getErrorArray(){
81 return $this->errors;