X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=functions%2Fforms.php;h=3583a33fc3849405a325f80f8c75a87f46d3f651;hp=850d58b8d31546fbbfbcb40ec77ab40f8ce8d2fb;hb=9d6b3b72a34621d96ba77b1d4b3072f1c4e6ab7f;hpb=493b168df7926d17bd82995926f75f812f124903 diff --git a/functions/forms.php b/functions/forms.php index 850d58b8..3583a33f 100644 --- a/functions/forms.php +++ b/functions/forms.php @@ -8,35 +8,44 @@ * Functions to build HTML forms in a safe and consistent manner. * All name, value attributes are htmlentitied. * - * $Id$ + * @version $Id$ * @package squirrelmail + * @subpackage forms */ /** * Helper function to create form fields, not to be called directly, * only by other functions below. */ -function addInputField($type, $name, $value, $attributes = '') { - return '\n"; +function addInputField($type, $name = null, $value = null, $attributes = '') { + return '\n"; +} + +/** + * Password input field + */ +function addPwField($name , $value = null) { + return addInputField('password', $name , $value); } /** * Form checkbox */ -function addCheckBox($name, $checked = false, $value='') { +function addCheckBox($name, $checked = false, $value = null) { return addInputField('checkbox', $name, $value, - ($checked ? ' checked' : '')); + ($checked ? ' checked="checked"' : '')); } /** * Form radio box */ -function addRadioBox($name, $checked = false, $value='') { - return addInputField('radio', $name, $value, - ($checked ? ' checked' : '')); +function addRadioBox($name, $checked = false, $value = null) { + return addInputField('radio', $name, $value, + ($checked ? ' checked="checked"' : '')); } /** @@ -77,29 +86,43 @@ function addSelect($name, $values, $default = null, $usekeys = false) if(count($values) == 1) { $k = key($values); $v = array_pop($values); return addHidden($name, ($usekeys ? $k:$v)). - htmlentities($v) . "\n"; + htmlspecialchars($v) . "\n"; } - $ret = '\n"; foreach ($values as $k => $v) { if(!$usekeys) $k = $v; $ret .= '\n"; + htmlspecialchars( $k ) . '"' . + (($default == $k) ? ' selected="selected"':'') . + '>' . htmlspecialchars($v) ."\n"; } $ret .= "\n"; return $ret; } +/** + * Form submission button + * Note the switched value/name parameters! + */ +function addSubmit($value, $name = null) { + return addInputField('submit', $name, $value); +} +/** + * Form reset button, $value = caption + */ +function addReset($value) { + return addInputField('reset', null, $value); +} + /** * Textarea form element. */ function addTextArea($name, $text = '', $cols = 40, $rows = 10, $attr = '') { - return '\n"; + $attr . '">'.htmlspecialchars($text) ."\n"; } /** @@ -118,7 +141,7 @@ function addForm($action, $method = 'POST', $name = '', $enctype = '', $charset } return '
\n"; + $enctype . $name . $charset . ">\n"; } - +?>