diff --git a/form.php b/form.php index dd9ed59..1c33634 100644 --- a/form.php +++ b/form.php @@ -34,23 +34,25 @@ class form $this->formName = $formName; } - /** Save the fields into the structure. + /** Save the array of fields into the structure. Available : - - name : name of the field in the HTML page - - label : label written to the describe the field - - [titles] : text written in radio/checkboxes - - [defaults] : default values. Must be array for checkbox/select, and - string for others - - [type] : text, password, hidden, checkbox, select, radio, submit, - textarea - text by default - - [multiple] : Multiple selection are possible (if the type supports it) - - [group] : define a fieldset and define the title with groupe name - Warning : all the elements of the same group must be - consecutive ! - - [readonly] : put a read-only flag on the field (the user see it but - can't interract on it. The value will be sent to next - page + - name : name of the field in the HTML page + - label : label written to the describe the field + - [titles] : text written in radio/checkboxes + - [defaults] : default values. Must be array for checkbox/select, and + string for others + - [type] : text, password, hidden, checkbox, select, radio, submit, + textarea + text by default + - [help] : The Help message (written below the field). Overwrite in + case of error + - [multiple] : Multiple selection are possible (if the type supports it) + - [group] : define a fieldset and define the title with groupe name + Warning : all the elements of the same group must be + consecutive ! + - [readonly] : put a read-only flag on the field (the user see it but + can't interract on it. The value will be sent to next + page - [mandatory] : boolean to add a red star at end of label - [hidden] : hide the field (add a style='display:hidden' to the field) - [rows] : Number of rows @@ -63,6 +65,13 @@ class form $this->fields = $fields; } + /** Add a field to the form. For the details of a field, see the description + in fields method */ + public function addfield ($field) + { + $this->fields[] = $field; + } + /** Return the values provided by the user. Test the CSRF before continue NEVER read the values from $_POST in your codes or CSRF will not be checked */ @@ -129,6 +138,8 @@ class form public function printHTML ($method = 'post', $values = NULL, $errors = array()) { + if (count ($this->fields) === 0) + throw new Exception ("Can't display a form without defined field", 500); $this->method = strtolower ($method); $res = ""; $res = "