Manual:HTMLForm Tutorial 2/de

Der Rest dieser Seite befasst sich mit der Verwendung von HTML Formular durch generische -Einträge (Einstellungen, die für alle Feldtypen gelten). Wir arbeiten daher nur an  'HTMLTextField'  Eingaben.

Überspringe den allgemeinen Teil und gehe direkt zu den Feldspezifikation

Here we are in And working on the   function...

Adding a Simple Text Field
Let's replace "Hello World" by a text field called Now, the form looks like:



Adding Callback
Sadly, the previous code displays the form, but the form doesn't work. We need to write some logic to process the form input! Now, the form processes the submitted data:



Submission method
The form can be set to use either the POST or GET submission method.


 * POST (default): The form fields' contents are not shown in the page URL. This method should be used for forms that change the wiki content (e.g. edit pages or block users).


 * GET: The form fields' contents are shown in the page URL. The resulting URL can be bookmarked or linked to allow others to view it. However, submission of very long forms (multiple kilobytes of text) may fail. This method should be used for forms that do not change the wiki content (e.g. show a list of pages).

Wenn Du vor hast, die Daten über eine GET-Anforderung zu übermitteln, musst Du Folgendes hinzufügen:

Note that GET forms using a  or   field have to have a "form identifier" set to work correctly, same as if you were using multiple forms on one page – see Using multiple forms on a single page below.

Adding Validation
Fields can be individually validated before submit callback.

First we tell HTMLForm by adding this line: in : Then we write the validation logic: Now, the validation logic checks submitted data before processing:



Required Field
You can specify that a field is required by simply adding to the formDescriptor. Any validation-callback will overwrite required. If you want to validate a required field, add the following logic to your validation callback function:

Adding Filtering
Filtering happens BEFORE validation to change input.

formDescriptor declaration: Filtering logic:

Adding i18n support
Mit dieser Funktion kannst Du das Label in die Sprache übersetzen, die in den Benutzereinstellungen definiert ist. Ersetze einfach 'label' durch 'label-message' im formDescriptor, um die Zeichenfolge automatisch über die i18n-Routine abzurufen: Vergiss nicht, den richtigen Eintrag in die Dateien aufzunehmen. Zum Beispiel hier in Englisch und Französisch:

For the submit button, we need to do it "manually": Of course, as always, you'll need to add the myform-submit entry in the localization files.

Adding sections
Now, we need to add some fields and organize them, let's switch to a bigger formDescriptor.

The section string displayed is automatically fetched from the localization files. Here we therefore need to add this in en.json :

Now, the form looks like:



Subsections
Sections can be easily nested with the incredible power of /.

The i18n ID will be like:

Now, the form looks like:



Adding Help-text
What about providing users with instructions to use your form easily? or  (an i18n message name) are here for you.

Now, the form looks like:



Adding html CLASS and ID
and  are here for you.

Changing Name of input
By default, input name is, for the previous example, the input name is therefore. This can be changed with : Just to give you an idea, here is the HTML output generated:

Disabling input
disabled is there and the user cannot copy (CTRL-C) input. The item will not be valid for submission. As simple as that!

Turning input read-only
readonly ist vorhanden und der Benutzer kann keine Eingaben ändern. Again, as simple as that!

Using multiple forms on a single page
If you use multiple forms on a single special page (e.g. one to show search results, and another to modify a result), you need to set a "form identifier" to allow HTMLForm to detect which of the forms was submitted. The identifier can be any string, and it must be different for every form.

For technical reasons, this is also necessary when using a  or   field in a GET form; otherwise HTMLForm can't detect whether the form was submitted and therefore whether it should load the default values or not.

NEXT PAGE OF THE TUTORIAL