From: tokul Date: Sun, 29 May 2005 08:30:57 +0000 (+0000) Subject: documenting form functions. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ed6d3334c44c7032904a527b8a69364463ce5c67;p=squirrelmail.git documenting form functions. adding id tag support to every function instead of using it only in main function. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@9469 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/functions/forms.php b/functions/forms.php index 24e00e91..5f515d2b 100644 --- a/functions/forms.php +++ b/functions/forms.php @@ -1,21 +1,42 @@ passwall.com. Tags can be used for Section 508 + * or WAI compliance. + * + * @link http://www.section508.gov/ Section 508 + * @link http://www.w3.org/WAI/ Web Accessibility Initiative (WAI) + * @link http://www.w3.org/TR/html4/ W3.org HTML 4.01 form specs * @version $Id$ * @package squirrelmail * @subpackage forms + * @since 1.4.3 and 1.5.1 */ /** * Helper function to create form fields, not to be called directly, * only by other functions below. + * @param string $type type of input field. Possible values (html 4.01 + * specs.): text, password, checkbox, radio, submit, reset, file, + * hidden, image, button. + * @param string $name form field name + * @param string $value initial field value + * @param string $attributes extra attributes + * @param string $id (since 1.5.1) assigns unique identifier to an element + * @return string html formated input field + * @deprecated use other functions that provide simple wrappers to this function */ function addInputField($type, $name = null, $value = null, $attributes = '', $id = null) { return ' value ) -> - * default: the key that will be selected - * usekeys: use the keys of the array as option value or not + * @param string $name field name + * @param array $values field values array ( key => value ) -> + * @param mixed $default the key that will be selected + * @param boolean $usekeys use the keys of the array as option value or not + * @param string $id (since 1.5.1) assigns unique identifier to an element + * @return string html formated selection box */ -function addSelect($name, $values, $default = null, $usekeys = false) -{ +function addSelect($name, $values, $default = null, $usekeys = false, $id = null) { // only one element if(count($values) == 1) { $k = key($values); $v = array_pop($values); - return addHidden($name, ($usekeys ? $k:$v)). + return addHidden($name, ($usekeys ? $k:$v), $id). htmlspecialchars($v) . "\n"; } - $ret = '\n"; foreach ($values as $k => $v) { if(!$usekeys) $k = $v; $ret .= '\n"; + '>' . $label_open . htmlspecialchars($v) . $label_close ."\n"; } $ret .= "\n"; @@ -107,31 +165,62 @@ function addSelect($name, $values, $default = null, $usekeys = false) /** * Form submission button * Note the switched value/name parameters! + * @param string $value button name + * @param string $name submitted key name + * @param string $id (since 1.5.1) assigns unique identifier to an element + * @return string html formated submit input field */ -function addSubmit($value, $name = null) { - return addInputField('submit', $name, $value); +function addSubmit($value, $name = null, $id = null) { + return addInputField('submit', $name, $value, '', $id); } /** - * Form reset button, $value = caption + * Form reset button + * @param string $value button name + * @param string $id (since 1.5.1) assigns unique identifier to an element + * @return string html formated reset input field */ -function addReset($value) { - return addInputField('reset', null, $value); +function addReset($value, $id = null) { + return addInputField('reset', null, $value, '', $id); } /** * Textarea form element. + * @param string $name field name + * @param string $text initial field value + * @param integer $cols field width (number of chars) + * @param integer $rows field height (number of character rows) + * @param string $attr extra attributes + * @param string $id (since 1.5.1) assigns unique identifier to an element + * @return string html formated text area field */ -function addTextArea($name, $text = '', $cols = 40, $rows = 10, $attr = '') { +function addTextArea($name, $text = '', $cols = 40, $rows = 10, $attr = '', $id = '') { + if (!empty($id)) { + $id = ' id="'. htmlspecialchars($id) . '"'; + $label_open = ''; + } else { + $label_open = ''; + $label_close = ''; + } return '\n"; + $attr . $id . '>'. $label_open . htmlspecialchars($text) . $label_close ."\n"; } /** * Make a
start-tag. + * @param string $action form handler URL + * @param string $method http method used to submit form data. 'get' or 'post' + * @param string $name form name used for identification (used for backward + * compatibility). Use of id is recommended. + * @param string $enctype content type that is used to submit data. html 4.01 + * defaults to 'application/x-www-form-urlencoded'. Form with file field needs + * 'multipart/form-data' encoding type. + * @param string $charset charset that is used for submitted data + * @param string $id (since 1.5.1) assigns unique identifier to an element + * @return string html formated form start string */ -function addForm($action, $method = 'post', $name = '', $enctype = '', $charset = '') -{ +function addForm($action, $method = 'post', $name = '', $enctype = '', $charset = '', $id = '') { if($name) { $name = ' name="'.$name.'"'; } @@ -141,9 +230,12 @@ function addForm($action, $method = 'post', $name = '', $enctype = '', $charset if($charset) { $charset = ' accept-charset="'.htmlspecialchars($charset).'"'; } + if (!empty($id)) { + $id = ' id="'.htmlspecialchars($id).'"'; + } return '\n"; + $enctype . $name . $charset . $id . ">\n"; } ?> \ No newline at end of file