Soporte para editar comentarios.
[ecomupi.git] / include / form.php
blob182c37e493896023c047ffea13c5bf065a405cdd
1 <?
2 class Form
4 var $values = array(); //Holds submitted form field values
5 var $errors = array(); //Holds submitted form error messages
6 var $num_errors; //The number of errors in submitted form
8 /* Class constructor */
9 function Form(){
10 /**
11 * Get form value and error arrays, used when there
12 * is an error with a user-submitted form.
14 if(isset($_SESSION['value_array']) && isset($_SESSION['error_array'])){
15 $this->values = $_SESSION['value_array'];
16 $this->errors = $_SESSION['error_array'];
17 $this->num_errors = count($this->errors);
19 unset($_SESSION['value_array']);
20 unset($_SESSION['error_array']);
22 else{
23 $this->num_errors = 0;
27 /**
28 * setValue - Records the value typed into the given
29 * form field by the user.
31 function setValue($field, $value){
32 $this->values[$field] = $value;
35 /**
36 * setError - Records new form error given the form
37 * field name and the error message attached to it.
39 function setError($field, $errmsg){
40 $this->errors[$field] = $errmsg;
41 $this->num_errors = count($this->errors);
44 /**
45 * value - Returns the value attached to the given
46 * field, if none exists, the empty string is returned.
48 function value($field){
49 if(array_key_exists($field,$this->values)){
50 return htmlspecialchars(stripslashes($this->values[$field]));
51 }else{
52 return "";
56 /**
57 * error - Returns the error message attached to the
58 * given field, if none exists, the empty string is returned.
60 function error($field){
61 if(array_key_exists($field,$this->errors)){
62 return "<font size=\"2\" color=\"#ff0000\">".$this->errors[$field]."</font>";
63 }else{
64 return "";
68 /* getErrorArray - Returns the array of error messages */
69 function getErrorArray(){
70 return $this->errors;