HTMLForm

From MediaWiki.org
Jump to: navigation, search

HTMLForm is a class for handling everything related to user interface forms. It was introduced by Werdna in r48740 as a part of his preferences system rewrite. MediaWiki 1.16 and newer include HTMLForm in HTMLForm.php.

Historically MediaWikis from version 1.4.0 to version 1.11 included a different HTMLForm class, written by Hashar and JeLuF. This HTMLForm was removed in r29245 by Simetrical.

HTMLForm/tutorial shows basics of HTMLForm .

[edit] Example usage

<?php
 
class SpecialTestForm extends SpecialPage {
        public function __construct() {
                parent::__construct( 'TestForm' );
        }
 
        public function execute( $par ) {
                global $wgOut;
 
                $wgOut->setPageTitle( 'LOL TEST FORM' );
 
                $formDescriptor = array(
                        'myfield1' => array(
                                'section' => 'section1/subsection',
                                'label-message' => 'testform-myfield1',
                                'class' => 'HTMLTextField',
                                'default' => 'Meep',
                        ),
                        'myfield2' => array(
                                'section' => 'section1',
                                'label-message' => 'testform-myfield2',
                                'class' => 'HTMLTextField',
                        ),
                        'myfield3' => array(
                                'class' => 'HTMLTextField',
                                'label' => 'Foo bar baz',
                        ),
                        'myfield4' => array(
                                'class' => 'HTMLCheckField',
                                'label' => 'This be a pirate checkbox',
                                'default' => true,
                        ),
                        'omgaselectbox' => array(
                                'class' => 'HTMLSelectField',
                                'label' => 'Select an oooption',
                                'options' => array(
                                        'pirate' => 'Pirates',
                                        'ninja' => 'Ninjas',
                                        'ninjars' => 'Back to the NINJAR!'
                                ),
                        ),
                        'omgmultiselect' => array(
                                'class' => 'HTMLMultiSelectField',
                                'label' => 'Weapons to use',
                                'options' => array( 'cannon' => 'Cannons', 'sword' => 'Swords' ),
                                'default' => array( 'sword' ),
                        ),
                        'radiolol' => array(
                                'class' => 'HTMLRadioField',
                                'label' => 'Who do you like?',
                                'options' => array(
                                        'pirates' => 'Pirates',
                                        'ninjas' => 'Ninjas',
                                        'both' => 'Both'
                                ),
                                'default' => 'pirates',
                        ),
                );
 
                $htmlForm = new HTMLForm( $formDescriptor, 'testform' );
 
                $htmlForm->setSubmitText( 'Foo submit' );
                $htmlForm->setTitle( $this->getTitle() );
                $htmlForm->setSubmitCallback( array( 'SpecialTestForm', 'trySubmit' ) );
 
                $htmlForm->show();
        }
 
        static function trySubmit( $formData ) {
                if ( $formData['myfield1'] == 'Fleep' ) {
                        return true;
                }
 
                return 'HAHA FAIL';
        }
}
 
$wgSpecialPages['TestForm'] = 'SpecialTestForm';

[edit] Parameters

Documenting the parameters for HTMLForm forms so they don't get lost

Precise specification for:


type
class
size
maxlength
min
max
invert
options
section
label-message
label
id
validation-callback
filter-callback
help-message
help

[edit] See also

Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox