From 493b168df7926d17bd82995926f75f812f124903 Mon Sep 17 00:00:00 2001 From: kink Date: Sun, 28 Mar 2004 14:35:37 +0000 Subject: [PATCH] Functions to build HTML forms. I've created this for another project of mine, and think they come in useful here. They are kept simple on purpose. Advantage is less typing [eg addHidden('startMessage', $startMessage)] and everything is encoded automatically. Could be extended with submit/reset and other form elts not covered yet. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@6912 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/forms.php | 124 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 functions/forms.php diff --git a/functions/forms.php b/functions/forms.php new file mode 100644 index 00000000..850d58b8 --- /dev/null +++ b/functions/forms.php @@ -0,0 +1,124 @@ +\n"; +} + + +/** + * Form checkbox + */ +function addCheckBox($name, $checked = false, $value='') { + return addInputField('checkbox', $name, $value, + ($checked ? ' checked' : '')); +} + +/** + * Form radio box + */ +function addRadioBox($name, $checked = false, $value='') { + return addInputField('radio', $name, $value, + ($checked ? ' checked' : '')); +} + +/** + * A hidden form field. + */ +function addHidden($name, $value) { + return addInputField('hidden', $name, $value); +} + +/** + * An input textbox. + */ +function addInput($name, $value = '', $size = 0, $maxlength = 0) { + + $attr = ''; + if ($size) { + $attr.= ' size="'.(int)$size.'"'; + } + if ($maxlength) { + $attr.= ' maxlength="'.(int)$maxlength .'"'; + } + + return addInputField('text', $name, $value, $attr); +} + + +/** + * Function to create a selectlist from an array. + * Usage: + * name: html name attribute + * values: array ( key => value ) ->