850d58b8d31546fbbfbcb40ec77ab40f8ce8d2fb
5 * Copyright (c) 2004 The SquirrelMail Project Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 * Functions to build HTML forms in a safe and consistent manner.
9 * All name, value attributes are htmlentitied.
12 * @package squirrelmail
16 * Helper function to create form fields, not to be called directly,
17 * only by other functions below.
19 function addInputField($type, $name, $value, $attributes = '') {
20 return '<input type="'.$type.'" name="'.htmlentities($name).'" '.
21 ' value="'.htmlentities($value).'"'.
29 function addCheckBox($name, $checked = false, $value='') {
30 return addInputField('checkbox', $name, $value,
31 ($checked ?
' checked' : ''));
37 function addRadioBox($name, $checked = false, $value='') {
38 return addInputField('radio', $name, $value,
39 ($checked ?
' checked' : ''));
43 * A hidden form field.
45 function addHidden($name, $value) {
46 return addInputField('hidden', $name, $value);
52 function addInput($name, $value = '', $size = 0, $maxlength = 0) {
56 $attr.= ' size="'.(int)$size.'"';
59 $attr.= ' maxlength="'.(int)$maxlength .'"';
62 return addInputField('text', $name, $value, $attr);
67 * Function to create a selectlist from an array.
69 * name: html name attribute
70 * values: array ( key => value ) -> <option value="key">value
71 * default: the key that will be selected
72 * usekeys: use the keys of the array as option value or not
74 function addSelect($name, $values, $default = null, $usekeys = false)
77 if(count($values) == 1) {
78 $k = key($values); $v = array_pop($values);
79 return addHidden($name, ($usekeys ?
$k:$v)).
80 htmlentities($v) . "\n";
83 $ret = '<select name="'.htmlentities($name) . "\">\n";
84 foreach ($values as $k => $v) {
85 if(!$usekeys) $k = $v;
86 $ret .= '<option value="' .
87 htmlentities( $k ) . '"' .
88 (($default == $k) ?
' selected':'') .
89 '>' . htmlentities($v) ."</option>\n";
91 $ret .= "</select>\n";
97 * Textarea form element.
99 function addTextArea($name, $text = '', $cols = 40, $rows = 10, $attr = '') {
100 return '<textarea name="'.htmlentities($name).'" '.
101 'rows="'.(int)$rows .'" cols="'.(int)$cols.'"'.
102 $attr . '">'.htmlentities($text) ."</textarea>\n";
106 * Make a <form> start-tag.
108 function addForm($action, $method = 'POST', $name = '', $enctype = '', $charset = '')
111 $name = ' name="'.$name.'"';
114 $enctype = ' enctype="'.$enctype.'"';
117 $charset = ' accept-charset="'.htmlspecialchars($charset).'"';
120 return '<form action="'. $action .'" method="'. $method .'"'.
121 $enctype . $name . $charset . "\">\n";