extra quote removed
[squirrelmail.git] / functions / forms.php
index bf540d1dc87457e3c02f57098356b289e0170cd4..3583a33fc3849405a325f80f8c75a87f46d3f651 100644 (file)
@@ -8,8 +8,9 @@
  * Functions to build HTML forms in a safe and consistent manner.
  * All name, value attributes are htmlentitied.
  *
- * $Id$
+ * @version $Id$
  * @package squirrelmail
+ * @subpackage forms
  */
 
 /**
  */
 function addInputField($type, $name = null, $value = null, $attributes = '') {
     return '<input type="'.$type.'"'.
-        ($name  !== null ? ' name="'.htmlentities($name).'"'   : '').
-        ($value !== null ? ' value="'.htmlentities($value).'"' : '').
-        $attributes . ">\n";
+        ($name  !== null ? ' name="'.htmlspecialchars($name).'"'   : '').
+        ($value !== null ? ' value="'.htmlspecialchars($value).'"' : '').
+        $attributes . " />\n";
 }
 
 /**
  * Password input field
  */
-function addPwField($name) {
-    return addInputField('password', $name);
+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"' : ''));
 }
 
 /**
@@ -85,16 +86,16 @@ 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 = '<select name="'.htmlentities($name) . "\">\n";
+    $ret = '<select name="'.htmlspecialchars($name) . "\">\n";
     foreach ($values as $k => $v) {
         if(!$usekeys) $k = $v;
         $ret .= '<option value="' .
-            htmlentities( $k ) . '"' .
-            (($default == $k) ? ' selected':'') .
-            '>' . htmlentities($v) ."</option>\n";
+            htmlspecialchars( $k ) . '"' .
+            (($default == $k) ? ' selected="selected"':'') .
+            '>' . htmlspecialchars($v) ."</option>\n";
     }
     $ret .= "</select>\n";
 
@@ -119,9 +120,9 @@ function addReset($value) {
  * Textarea form element.
  */
 function addTextArea($name, $text = '', $cols = 40, $rows = 10, $attr = '') {
-    return '<textarea name="'.htmlentities($name).'" '.
+    return '<textarea name="'.htmlspecialchars($name).'" '.
         'rows="'.(int)$rows .'" cols="'.(int)$cols.'"'.
-        $attr . '">'.htmlentities($text) ."</textarea>\n";
+        $attr . '">'.htmlspecialchars($text) ."</textarea>\n";
 }
 
 /**
@@ -140,7 +141,7 @@ function addForm($action, $method = 'POST', $name = '', $enctype = '', $charset
     }
 
     return '<form action="'. $action .'" method="'. $method .'"'.
-        $enctype . $name . $charset . "\">\n";
+        $enctype . $name . $charset . ">\n";
 }
 
-
+?>