Difference between revisions of "Lat18/feedback"

From Numerical Transition Systems
Jump to: navigation, search
(Created page with "<?php class SpecialTestForm extends SpecialPage { public function __construct() { parent::__construct( 'TestForm' ); } public function execute( $par ) { $this->getOut...")
 
(Replaced content with "<?php echo 'hello' ?>")
 
Line 1: Line 1:
<?php
+
<?php echo 'hello' ?>
 
+
class SpecialTestForm extends SpecialPage {
+
public function __construct() {
+
parent::__construct( 'TestForm' );
+
}
+
 
+
public function execute( $par ) {
+
$this->getOutput()->setPageTitle( 'Test form' );
+
 
+
$formDescriptor = [
+
'myfield1' => [
+
'section' => 'section1/subsection',
+
'label-message' => 'testform-myfield1',
+
'type' => 'text',
+
'default' => 'Meep',
+
],
+
'myfield2' => [
+
'section' => 'section1',
+
'label-message' => 'testform-myfield2',
+
'class' => 'HTMLTextField', // same as type 'text'
+
],
+
'myfield3' => [
+
'class' => 'HTMLTextField',
+
'label' => 'Foo bar baz',
+
],
+
'myfield4' => [
+
'class' => 'HTMLCheckField',
+
'label' => 'This be a pirate checkbox',
+
'default' => true,
+
],
+
'omgaselectbox' => [
+
'class' => 'HTMLSelectField',
+
'label' => 'Select an oooption',
+
'options' => [
+
'Pirates' => 'pirate',
+
'Ninjas' => 'ninja',
+
'Back to the NINJAR!' => 'ninjars',
+
],
+
],
+
'omgmultiselect' => [
+
'class' => 'HTMLMultiSelectField',
+
'label' => 'Weapons to use',
+
'options' => [
+
'Cannons' => 'cannon',
+
'Swords' => 'sword',
+
],
+
'default' => [ 'sword' ],
+
],
+
'radiolol' => [
+
'class' => 'HTMLRadioField',
+
'label' => 'Who do you like?',
+
'options' => [
+
'Pirates' => 'pirates',
+
'Ninjas' => 'ninjas',
+
'Both' => 'both',
+
],
+
'default' => 'pirates',
+
],
+
];
+
 
+
$htmlForm = new HTMLForm( $formDescriptor, $this->getContext(), 'testform' );
+
 
+
$htmlForm->setSubmitText( 'Foo submit' );
+
$htmlForm->setSubmitCallback( [ $this, 'trySubmit' ] );
+
 
+
$htmlForm->show();
+
}
+
 
+
public function trySubmit( $formData ) {
+
if ( $formData[ 'myfield1' ] === 'Fleep' ) {
+
return true;
+
}
+
 
+
return 'Fail';
+
}
+
}
+
 
+
$wgSpecialPages['TestForm'] = 'SpecialTestForm';
+

Latest revision as of 16:55, 6 November 2018

<?php echo 'hello' ?>