WoltLab Suite 6.2 Handbuch
Deutsch/PHP-Version: Die Website-Struktur, Navigation und Überschriften sind auf Deutsch vorbereitet. Code-Beispiele und technische Namen bleiben unverändert.

Migrating from WSC 3.1 - Form Builder

Example: Two Text Form Fields

As the first example, the pre-WoltLab Suite Core 5.2 versions of the forms to add and edit persons from the first part of the tutorial series will be updated to the new form builder API.

This form is the perfect first examples as it is very simple with only two text fields whose only restriction is that they have to be filled out and that their values may not be longer than 255 characters each.

As a reminder, here are the two relevant PHP files and the relevant template file:

{jinja{ codebox(

title="files/lib/acp/form/PersonAddForm.class.php",

language="php",

filepath="migration/wsc-31/formBuilder/PersonAddForm_old.class.php"

) }}

{jinja{ codebox(

title="files/lib/acp/form/PersonEditForm.class.php",

language="php",

filepath="migration/wsc-31/formBuilder/PersonEditForm_old.class.php"

) }}

{jinja{ codebox(

title="acptemplates/personAdd.tpl",

language="smarty",

filepath="migration/wsc-31/formBuilder/personAdd_old.tpl"

) }}

Updating the template is easy as the complete form is replace by a single line of code:

{jinja{ codebox(

title="acptemplates/personAdd.tpl",

language="smarty",

filepath="migration/wsc-31/formBuilder/personAdd_new.tpl"

) }}

PersonEditForm also becomes much simpler:

only the edited Person object must be read:

{jinja{ codebox(

title="files/lib/acp/form/PersonEditForm.class.php",

language="php",

filepath="migration/wsc-31/formBuilder/PersonEditForm_new.class.php"

) }}

Most of the work is done in PersonAddForm:

{jinja{ codebox(

title="files/lib/acp/form/PersonAddForm.class.php",

language="php",

filepath="migration/wsc-31/formBuilder/PersonAddForm_new.class.php"

) }}

But, as you can see, the number of lines almost decreased by half.

All changes are due to extending AbstractFormBuilderForm: