title = $title; } /* Nouvelle section */ function sectionStart($legend='') { $l = end($this->fields); $j = $l->order + 1; $name = ($name == '') ? 'champ'.$j : $name; $this->fields[$j] = new conField($j, $legend, 'Fieldset', $name, '', '', '', '', '', ''); } /* Fin de section */ function sectionEnd() { $l = end($this->fields); $j = $l->order + 1; $name = ($name == '') ? 'champ'.$j : $name; $this->fields[$j] = new conField($j, '', 'Fieldset_end', $name, '', '', '', '', '', ''); } /* Ajout d'un champ */ public function addField($label='', $type='Text', $name='', $default='', $class='', $info='', $validIf='', $okValues='', $required = 'false') { $l = end($this->fields); $j = $l->order + 1; $name = ($name == '') ? 'champ'.$j : $name; $this->fields[$j] = new conField($j, $label, $type, $name, $default, $class, $info, $validIf, $okValues, $required); } /* Ajout d'un bloc dynamique */ public function addDynBlock() { $l = end($this->fields); $j = $l->order + 1; $name = ($name == '') ? 'champ'.$j : $name; $this->fields[$j] = new DynBlock(); } /* Ajout d'un commentaire */ function add_comment($text='') { $l = end($this->fields); $j = $l->order + 1; $name = ($name == '') ? 'champ'.$j : $name; $this->fields[$j] = new conField($j, $text, 'Comment', $name, '', '', '', '', '', ''); } /* Mise à jour du formulaire (via POST)*/ function update($post) { foreach( $this->fields as $field ) { $i = $field->order; $name = $field->name; $this->fields[$i]->value = isset($post[$name]) ? $post[$name] : ''; $this->fields[$i]->status = isset($post[$name]) ? 'on' : 'off'; } } /* Validation Serveur */ function serverValid() { $errors = 0; foreach ($this->fields as $field) { switch ($field->type) { case "Fieldset": break; case "Hidden": break; default: if (!($field->fieldValidation())){$errors++;} break; } } if ($errors == 0) { $validation = true; $this->_generalWarning = ""; } else { $validation = false; $this->_generalWarning = "Erreur(s) de saisie"; } return $validation; } /* Recupération d'une valeur d'après le nom d'un champ*/ public function getValue($fieldName) { $value = null; foreach ($this->fields as $field) { if ($field->name == $fieldName) { $value = $field->value; break; } } return $value; } /*Reset de toutes les valeurs*/ public function resetValues() { foreach ($this->fields as &$field) { switch ($field->type) { case "Fieldset": break; case "Hidden": break; default: $field->value=''; break; } } return true; } /* Affichage du formulaire */ public function display() { $xhtml = $this->header(); foreach ($this->fields as $field) { $xhtml .= $field->uDisplay(); } $xhtml .= $this->footer(); return $xhtml; } /* Entete de formulaire */ function header() { $xhtml = "" ; if ($this->title != '') { $xhtml .= "
".$this->_generalWarning."
"; } $xhtml .= " "; return $xhtml; } /** * Sortie standard */ public function output($level = 0) { parent::output($level); } } ?>