class to build forms (c) JeLuF
authorAntoine Musso <hashar@users.mediawiki.org>
Thu, 30 Sep 2004 22:49:26 +0000 (22:49 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Thu, 30 Sep 2004 22:49:26 +0000 (22:49 +0000)
includes/HTMLForm.php [new file with mode: 0644]

diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php
new file mode 100644 (file)
index 0000000..e7f0bd0
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+
+/**
+ * Class to build various forms
+ */
+class HTMLForm {
+       /* private */ function fieldset( $name, $content ) {
+               return "<fieldset><legend>".wfMsg($name)."</legend>\n" .
+                       $content . "\n</fieldset>\n";
+       }
+
+       /* private */ function checkbox( $varname, $checked=false ) {
+               $checked = isset( $GLOBALS[$varname] ) && $GLOBALS[$varname] ;
+               return "<div><input type='checkbox' value=\"1\" id=\"{$varname}\" name=\"wpOp{$varname}\"" .
+                       ( $checked ? ' checked="checked"' : '' ) .
+                       " /><label for=\"{$varname}\">". wfMsg( "sitesettings-".$varname ) .
+                       "</label></div>\n";
+       }
+
+       /* private */ function textbox( $varname, $value='', $size=20 ) {
+               $value = isset( $GLOBALS[$varname] ) ? $GLOBALS[$varname] : '';
+               return "<div><label>". wfMsg( "sitesettings-".$varname ) .
+                       "<input type='text' name=\"wpOp{$varname}\" value=\"{$value}\" size=\"{$size}\" /></label></div>\n";
+       }
+       /* private */ function radiobox( $varname, $fields ) {
+               foreach ( $fields as $value => $checked ) {
+                       $s .= "<div><label><input type='radio' name=\"wpOp{$varname}\" value=\"{$value}\"" .
+                               ( $checked ? ' checked="checked"' : '' ) . " />" . wfMsg( 'sitesettings-'.$varname.'-'.$value ) .
+                               "</label></div>\n";
+               }
+               return $this->fieldset( 'sitesettings-'.$varname, $s );
+       }
+
+       /* private */ function arraybox( $varname , $size=20 ) {
+               $s = '';
+               if ( isset( $GLOBALS[$varname] ) && is_array( $GLOBALS[$varname] ) ) {
+                       foreach ( $GLOBALS[$varname] as $index=>$element ) {
+                               $s .= $element."\n";
+                       }
+               }
+               return "<div><label>".wfMsg( 'sitesettings-'.$varname ).
+                       "<textarea name=\"wpOp{$varname}\" rows=\"5\" cols=\"{$size}\">{$s}</textarea>\n";
+       }
+}
+?>