Talk:HTMLForm

About this board

ArchATempAcct (talkcontribs)

I am an html and php coder and I am still finding this confusing.


All I want to do is have a small input box and a send button that anybody, even non-members can type a single sentence blurb, and it will be emailed to me. I don't need to email them back or anything. (Or it can go to a textfile, wikipage, or wherever) Just a one sentence blurb. What is the best way to do this simple thing?

Reply to "Mail"
Mhohner (talkcontribs)

I've used the "required" parameter for a checkbox, expecting that this would result in a HTML input element with the "required" attribute set. But this is not the case. Neither is the HTML attribute used, nor is the form checked for a non-empty value (i.a.w., selecting the checkbox is not enforced).

Mhohner (talkcontribs)

Same with type="radio". The "required" parameter has no effect. The user is not forced to select a non-empty option.

Reply to ""required" attribute"
Tim.landscheidt (talkcontribs)

I'm working on an extension similar in usage to Booksources. I want to achieve the following behaviour:

  1. If no parameters are supplied, an empty form is displayed.
  2. If some parameters or parameters with errors are supplied, a form preset with the parameters and any error messages is displayed.
  3. If all parameters are valid, a function is executed.

However with $htmlForm->setMethod ('get'), while parameter ranges are checked (e. g. lat=5555) and such errors yield in the display of a form, missing required parameters (e. g. omitting lat) or supplying no parameters at all doesn't display a form, but executes the submit callback.

With $htmlForm->setMethod ('post'), a form is always displayed and the submit callback never executed unless subsequently clicked by the user, but also the fields are preset with the values from the GET query string, but no error messages are displayed for parameters out of bounds.

As the class still seems to be in flux, I don't want to file a bug, but start a discussion.

Reply to "setMethod ()"

preparing pages for translation

3
Summary by Wladek92

done; thanks.

Wladek92 (talkcontribs)

Hi all just two questions concerning this article:

- why not assigned to a specific namespace (manual...)? we keep as it is or which namespace to use instead ?

- reference inside of this EN page is done to 2 tutorial sub pages left in ENglish. Is it worth to prepare then both for translation to have a coherent set of articles ?

Thank you.

Christian Wia (talk) 13:57, 29 July 2019 (UTC)

Mainframe98 (talkcontribs)

I've gone and updated tutorial 2. I've also prepared it for translation.

As far as I'm concerned, these pages should be in the manual namespace, and I'd recommend moving them before marking the other tutorials for translation - that way they can be updated easier.

Also the naming convention of page 2 and 3 is strange, so those should be moved to /tutorial 2 and tutorial 3 respectively.

I'll just be bold and rename them.

Wladek92 (talkcontribs)

Thank you for the move and the preparation. I have enough details to continue the work and will complete the FR translations pages correlated with the EN pages.

Christian Wia (talk) 18:39, 29 July 2019 (UTC)

VolkoV (talkcontribs)

I could only get this to work by changing the first part of the array to $this instead of string with the class name, following the manual of is_callable (http://php.net/manual/de/function.is-callable.php), meaning:

$htmlForm->setSubmitCallback( array( 'SpecialTestForm', 'trySubmit' ) )

should be

$htmlForm->setSubmitCallback( array( $this, 'trySubmit' ) )
Mainframe98 (talkcontribs)

Curious, since the code of the Preferences form uses the first variant, and that works. (source). Is the submit function defined as public static? If it isn't, the first variant won't work.

Reply to "setSubmitCallback"

htmlform-select-badoption errors

1
Rstockbower (talkcontribs)

If you're building a select dropdown and you're getting htmlform-select-badoption errors, try adding a default value. This array was throwing errors:

Array
(
    [Amsterdam] => AMS
    [Barcelona] => BCN
    [Berlin] => BER
    [Bhiwandi] => BHI
    [Deer Park] => DPK
    [The Hague] => HAG
    [Hong Kong] => HKG
    [Lexington] => LEX
    [Montego Bay] => MBY
    [Mumbai] => MUM
    [Paris] => PAR
    [Silver Spring] => SSM
    [Singapore] => SGP
    [Sydney] => SYD
    [Tunis] => TUN
    [Vadodara] => VAD
    [Venlo] => VEN
    [Windsor] => WND
    [Winterthur] => WTR
)

Copying the array from the tutorial did not throw errors:

Array
(
    [Option 0] => 0
    [Option 1] => 1
    [Option 2] => option2id
)

Note that their structures are the same; one is just a bit more complex than the other.

Making an explicit default got rid of the error message:

'office' => array(
	'name' => 'office',
	'type' => 'select',
	'label' => wfMessage('in-office')->parse(),
	'section' => 'convert-from-section-label',
	'options' => $this->buildOfficeList(),
	'default' => self::BLANK,
),
Reply to "htmlform-select-badoption errors"

Getting an OutPutPage object in the callback.

1
JimHu (talkcontribs)

From looking at the code in MW1.25.1 there is a feature that is not documented here. The callback sends not only the page data but also a reference to the HTMLform object itself. This means you can accept the object in your callback function and use it to get an OutPutPage object, which can be very useful for having your form do things like redirect to another page.

static function processInput( $formData, $htmlform ) {
          $t = Title::newFromText( $formData['new_page_name']);
          $content = $formData['page_content'];
          $reason = $formData['reason'];
          $p = new WikiPage($t);
          $p->save($content, $reason);
          $out = $htmlform->getOutput();
          $out->redirect($t->getFullURL());
           return true;  
}

Order of "options" values

1
Peachey88 (Flood) (talkcontribs)

Could it be that the values for "options" in the examples are in the wrong order? E. g., that:

'options' => array(
        'Pirates' => 'pirate',
        'Ninjas' => 'ninja',
        'Back to the NINJAR!' => 'ninjars'
),

would be needed to present the user with the choices "Pirates", "Ninjas", and "Back to the NINJAR!"? -- P. S.: Really nice and very useful gimmick!

This post was posted by Peachey88 (Flood), but signed as Tim.landscheidt.

Reply to "Order of "options" values"

Possible to embed form elements?

2
Rstockbower (talkcontribs)

Suppose I have two radio buttons. I want the first one to be something like:

"Use the current date and time in dropdown_of_possible_cities"

Can something like that be done with HTMLForms?

ClementD (talkcontribs)

No. To my knowledge the only advanced (dynamic) field is selectOrOther. This is NOT what you need but it might be a start. Good luck!

Reply to "Possible to embed form elements?"

Non-mandatory "select" fields

1
Tim.landscheidt (talkcontribs)

If a field of the select type has no required parameter, I'd assume that:

  1. the user has a choice to select no option for this field (e. g. a blank item), and
  2. if no value is supplied via a GET parameter, that this does not yield an error.

Yet at the moment, HTMLForm seems to demand otherwise.

Reply to "Non-mandatory "select" fields"
There are no older topics
Return to "HTMLForm" page.