class to build forms (c) JeLuF
[lhc/web/wiklou.git] / includes / HTMLForm.php
1 <?php
2
3 /**
4 * Class to build various forms
5 */
6 class HTMLForm {
7 /* private */ function fieldset( $name, $content ) {
8 return "<fieldset><legend>".wfMsg($name)."</legend>\n" .
9 $content . "\n</fieldset>\n";
10 }
11
12 /* private */ function checkbox( $varname, $checked=false ) {
13 $checked = isset( $GLOBALS[$varname] ) && $GLOBALS[$varname] ;
14 return "<div><input type='checkbox' value=\"1\" id=\"{$varname}\" name=\"wpOp{$varname}\"" .
15 ( $checked ? ' checked="checked"' : '' ) .
16 " /><label for=\"{$varname}\">". wfMsg( "sitesettings-".$varname ) .
17 "</label></div>\n";
18 }
19
20 /* private */ function textbox( $varname, $value='', $size=20 ) {
21 $value = isset( $GLOBALS[$varname] ) ? $GLOBALS[$varname] : '';
22 return "<div><label>". wfMsg( "sitesettings-".$varname ) .
23 "<input type='text' name=\"wpOp{$varname}\" value=\"{$value}\" size=\"{$size}\" /></label></div>\n";
24 }
25 /* private */ function radiobox( $varname, $fields ) {
26 foreach ( $fields as $value => $checked ) {
27 $s .= "<div><label><input type='radio' name=\"wpOp{$varname}\" value=\"{$value}\"" .
28 ( $checked ? ' checked="checked"' : '' ) . " />" . wfMsg( 'sitesettings-'.$varname.'-'.$value ) .
29 "</label></div>\n";
30 }
31 return $this->fieldset( 'sitesettings-'.$varname, $s );
32 }
33
34 /* private */ function arraybox( $varname , $size=20 ) {
35 $s = '';
36 if ( isset( $GLOBALS[$varname] ) && is_array( $GLOBALS[$varname] ) ) {
37 foreach ( $GLOBALS[$varname] as $index=>$element ) {
38 $s .= $element."\n";
39 }
40 }
41 return "<div><label>".wfMsg( 'sitesettings-'.$varname ).
42 "<textarea name=\"wpOp{$varname}\" rows=\"5\" cols=\"{$size}\">{$s}</textarea>\n";
43 }
44 }
45 ?>