From f063d6239baa0fc507b191789bf1c48d3dac1d6e Mon Sep 17 00:00:00 2001 From: Fedik Date: Sun, 20 Oct 2024 12:11:36 +0300 Subject: [PATCH 1/4] Form control fields --- .../forms/manipulating-forms.md | 36 +++++++++++++++++++ migrations/52-53/new-features.md | 34 ++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 migrations/52-53/new-features.md diff --git a/docs/general-concepts/forms/manipulating-forms.md b/docs/general-concepts/forms/manipulating-forms.md index f0dc58d6..76aac327 100644 --- a/docs/general-concepts/forms/manipulating-forms.md +++ b/docs/general-concepts/forms/manipulating-forms.md @@ -107,6 +107,42 @@ You can thus set the default attribute using `setFieldAttribute()`, but to set t ### Removing Fields You can remove fields from the Form definition by calling `removeField()` to remove a specific field or `removeGroup()` to remove all the fields within a specified field group. +## Control fields +While the form fields used for data handling in the Model, the Controller also requires a few fields, like `task`, `return`, and CSRF token. +Previously these fields were coded directly in to the form layout. + +Form class provides a methods to manage these control fields programmatically: +- `addControlField()` add control field to the form; +- `removeControlField()` remove control field from the form; +- `getControlFields()` get list of control fields in the form; +- `renderControlFields()` render the control fields; + +While rendering the control fields the CSRF token will always be rendered, no need to add it to list of control fields. + +### Use of control fields example + +Before: +```html + + + + +``` + +With control fields: +```php +// Code in Controller/View +$this->form + ->addControlField('task', '') + ->addControlField('foo', 'bar') + ->addControlField('return', $input->getBase64('return', '')); + +// Code in the form layout +echo $this->form->renderControlFields(); +``` + + + ## Reflection Methods There are a number of methods which allow you to access various aspects of the Form instance data. Mostly these are fairly straightforward to understand, and only cases where it may not be totally clear are explained below. diff --git a/migrations/52-53/new-features.md b/migrations/52-53/new-features.md new file mode 100644 index 00000000..57c53c24 --- /dev/null +++ b/migrations/52-53/new-features.md @@ -0,0 +1,34 @@ +--- +sidebar_position: 1 +--- + +# New features + +#### Form control fields + +New methods to manage form control fields. +More detail at [Form Control fields](/docs/general-concepts/forms/manipulating-forms.md#control-fields) + +PR: https://github.com/joomla/joomla-cms/pull/43857 + +**Example** + +Before: +```html + + + + +``` + +After: +```php +// Code in Controller/View +$this->form + ->addControlField('task', '') + ->addControlField('foo', 'bar') + ->addControlField('return', $input->getBase64('return', '')); + +// Code in the form layout +echo $this->form->renderControlFields(); +``` From ddf3627c29e3d12ebc01e4331d43a35360f0a723 Mon Sep 17 00:00:00 2001 From: Fedik Date: Sun, 20 Oct 2024 12:25:10 +0300 Subject: [PATCH 2/4] link --- migrations/52-53/new-features.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/52-53/new-features.md b/migrations/52-53/new-features.md index 57c53c24..56b2bdcc 100644 --- a/migrations/52-53/new-features.md +++ b/migrations/52-53/new-features.md @@ -7,7 +7,7 @@ sidebar_position: 1 #### Form control fields New methods to manage form control fields. -More detail at [Form Control fields](/docs/general-concepts/forms/manipulating-forms.md#control-fields) +More detail at [Form Control fields](docs/general-concepts/forms/manipulating-forms.md#control-fields) PR: https://github.com/joomla/joomla-cms/pull/43857 From 0fe237ad494660dbba58ffb154d1e0ac828acb9e Mon Sep 17 00:00:00 2001 From: Fedik Date: Sun, 20 Oct 2024 12:38:48 +0300 Subject: [PATCH 3/4] link --- migrations/52-53/new-features.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/52-53/new-features.md b/migrations/52-53/new-features.md index 56b2bdcc..bd64feed 100644 --- a/migrations/52-53/new-features.md +++ b/migrations/52-53/new-features.md @@ -7,7 +7,7 @@ sidebar_position: 1 #### Form control fields New methods to manage form control fields. -More detail at [Form Control fields](docs/general-concepts/forms/manipulating-forms.md#control-fields) +More detail at [Form Control fields](../../docs/general-concepts/forms/manipulating-forms#control-fields) PR: https://github.com/joomla/joomla-cms/pull/43857 From b681960e88de503121df7b73f86966d100a5e1a4 Mon Sep 17 00:00:00 2001 From: Fedik Date: Sat, 16 Nov 2024 11:39:22 +0200 Subject: [PATCH 4/4] form control fields --- docs/general-concepts/forms/manipulating-forms.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/general-concepts/forms/manipulating-forms.md b/docs/general-concepts/forms/manipulating-forms.md index 76aac327..0fc2f5fb 100644 --- a/docs/general-concepts/forms/manipulating-forms.md +++ b/docs/general-concepts/forms/manipulating-forms.md @@ -118,6 +118,8 @@ Form class provides a methods to manage these control fields programmatically: - `renderControlFields()` render the control fields; While rendering the control fields the CSRF token will always be rendered, no need to add it to list of control fields. +The name `joomla.form.token` is reserved in the control fields list for Joomla default CSRF token field. +When in some reason need to remove default CSRF token then use `$form->removeControlField('joomla.form.token');` to remove it. ### Use of control fields example