comments
[lhc/web/wiklou.git] / includes / HTMLForm.php
1 <?php
2 /** */
3
4 /**
5 * Class to build various forms
6 */
7 class HTMLForm {
8 /** name of our form. Used as prefix for labels */
9 var $mName;
10
11 /**
12 * @access private
13 * @param string $name Name of the fieldset.
14 * @param string $content HTML content to put in.
15 * @return string HTML fieldset
16 */
17 function fieldset( $name, $content ) {
18 return "<fieldset><legend>".wfMsg($this->mName.'-'.$name)."</legend>\n" .
19 $content . "\n</fieldset>\n";
20 }
21
22 /*
23 * @access private
24 * @param string $varname Name of the checkbox.
25 * @param boolean $checked Set true to check the box (default False).
26 */
27 function checkbox( $varname, $checked=false ) {
28 $checked = isset( $GLOBALS[$varname] ) && $GLOBALS[$varname] ;
29 return "<div><input type='checkbox' value=\"1\" id=\"{$varname}\" name=\"wpOp{$varname}\"" .
30 ( $checked ? ' checked="checked"' : '' ) .
31 " /><label for=\"{$varname}\">". wfMsg( $this->mName.'-'.$varname ) .
32 "</label></div>\n";
33 }
34
35 /*
36 * @access private
37 * @param string $varname Name of the textbox.
38 * @param string $value Optional value (default empty)
39 * @param integer $size Optional size of the textbox (default 20)
40 */
41 function textbox( $varname, $value='', $size=20 ) {
42 $value = isset( $GLOBALS[$varname] ) ? $GLOBALS[$varname] : $value;
43 return "<div><label>". wfMsg( $this->mName.'-'.$varname ) .
44 "<input type='text' name=\"wpOp{$varname}\" value=\"{$value}\" size=\"{$size}\" /></label></div>\n";
45 }
46
47 /*
48 * @access private
49 * @param string $varname Name of the radiobox.
50 * @param array $fields Various fields.
51 */
52 function radiobox( $varname, $fields ) {
53 foreach ( $fields as $value => $checked ) {
54 $s .= "<div><label><input type='radio' name=\"wpOp{$varname}\" value=\"{$value}\"" .
55 ( $checked ? ' checked="checked"' : '' ) . " />" . wfMsg( $this->mName.'-'.$varname.'-'.$value ) .
56 "</label></div>\n";
57 }
58 return $this->fieldset( $this->mName.'-'.$varname, $s );
59 }
60
61 /*
62 * @access private
63 * @param string $varname Name of the textareabox.
64 * @param string $value Optional value (default empty)
65 * @param integer $size Optional size of the textarea (default 20)
66 */
67 function textareabox ( $varname, $value='', $size=20 ) {
68 $value = isset( $GLOBALS[$varname] ) ? $GLOBALS[$varname] : $value;
69 return '<div><label>'.wfMsg( $this->mName.'-'.$varname ).
70 "<textarea name=\"wpOp{$varname}\" rows=\"5\" cols=\"{$size}\">$value</textarea>\n";
71 }
72
73 /*
74 * @access private
75 * @param string $varname Name of the arraybox.
76 * @param integer $size Optional size of the textarea (default 20)
77 */
78 function arraybox( $varname , $size=20 ) {
79 $s = '';
80 if ( isset( $GLOBALS[$varname] ) && is_array( $GLOBALS[$varname] ) ) {
81 foreach ( $GLOBALS[$varname] as $index=>$element ) {
82 $s .= $element."\n";
83 }
84 }
85 return "<div><label>".wfMsg( $this->mName.'-'.$varname ).
86 "<textarea name=\"wpOp{$varname}\" rows=\"5\" cols=\"{$size}\">{$s}</textarea>\n";
87 }
88 }
89 ?>