Skip to content

Forms

To help separate concerns, forms come in multiple types.

The current form types are:

Common Functions

All forms come with some common functions that are required to complete the forms basic operations.

Load Function

TIP

For the Axios controller can process the response, your function must return a LoadResponse

The load function is included in the abstract class that both forms extend from, so it's not required to be added. If a child function doesn't override the parent function, this will return a blank form when loaded (no values in fields etc.).

Example Successful Response
php
return LoadResponse::make()->success()->form($form);
return LoadResponse::make()->success()->form($form);
Example Failed Response
php
return LoadResponse::make()->failed();
return LoadResponse::make()->failed();

Process Function

TIP

For the Axios controller can process the response, your function must return a ProcessResponse

The process function allows you to process requests that pass validation. You don't need to check for validation or conformity, you can just get straight to processing. Once the data reaches the process function the validation process has already passed successfully.

With Action Forms the process function doesn't need to be updated, but you do need to create functions for each callback you create for your actions.

Example Successful Response
php
return ProcessResponse::make()->success()->data('Success!');
return ProcessResponse::make()->success()->data('Success!');
Example Failed Response
php
return ProcessResponse::make()->failed()->data('Failed!');
return ProcessResponse::make()->failed()->data('Failed!');

All Forms

All forms come with the following properties:

PropertyTypeDefaultDescription
additional_dataAdditionalData[]undefinedArray of Additional Data passed when processing the form.
additional_load_dataAdditionalData[]undefinedArray of Additional Data passed when loading the form.
alertsAlert[]undefinedArray of Alerts
axiosAxiosundefinedAxios
loaderFormLoaderundefinedFormLoader
nameStringundefinedThe name of the form, this should include any additional namespace parameters.
titleStringundefinedThe title of the form displayed in a h2 tag, if left blank no title is shown.

Input Form

Input Forms are used when you need to take users input, this could any typical CRUD actions or something like logging in. The main difference is Input Forms contain fields (textfield, selectfield, pickers etc.). They can also be validated (including frontend validation).

PropertyTypeDefaultDescription
button_align_rowStringundefinedAlignment of row for buttons.
button_justify_rowStringundefinedJustify of row for buttons.
buttonsButtonundefinedArray of Buttons but must be one of Button Types
fieldsFieldundefinedArray of Fields

Action Form

Action forms are used when you want to display a group of icons or buttons that perform certain actions. You typically see these in data tables where you have the option to delete, edit, change uer status etc. They are also handy in dashboards when just needing a button to process something. The main difference is Action Forms contain action icons and action buttons (not fields). These perform certain specified actions provided in the form class.

PropertyTypeDefaultDescription
actionsActionIcon[], ActionButton[]undefinedArray of Action Buttons or Action Icons
inlineBooleanundefinedApply inline styling to actions
justifyStringcenterJustify of row holding actions

Adding Google V3 Recaptcha

Support has been added for google recaptcha V3. To add this to your form, you will need to setup an API key on google:

Google Recaptcha Admin Console

Inside your .env file you will need to add both the Site Key and Secret Key.

GOOGLE_RECAPTCHA_SITE_KEY=
GOOGLE_RECAPTCHA_SECRET_KEY=
GOOGLE_RECAPTCHA_SITE_KEY=
GOOGLE_RECAPTCHA_SECRET_KEY=

By default, inside the configuration the mode is set to global. This means that if a site key is provided in the .env file it will attempt to add recaptcha to all forms. If you want to exclude recaptcha from a particular form, you will need to set the google site key to null using the function setGoogleRecaptchaSiteKey (attached to all forms), inside your forms constructor like below:

php
public function __construct()
{
    parent::__construct();

    return $this
        ->setGoogleRecaptchaSiteKey(null)
        ->setName('ExampleForm')
        ->setTitle('This is an example form.');
}
public function __construct()
{
    parent::__construct();

    return $this
        ->setGoogleRecaptchaSiteKey(null)
        ->setName('ExampleForm')
        ->setTitle('This is an example form.');
}

You can also set the mode to explicit and this means you will need to set the site key on each form you want the recaptcha to be applied on.

php
public function __construct()
{
    parent::__construct();

    return $this
        ->setGoogleRecaptchaSiteKey(config('easyforms.form.google_recaptcha.site_key'))
        ->setName('ExampleForm')
        ->setTitle('This is an example form.');
}
public function __construct()
{
    parent::__construct();

    return $this
        ->setGoogleRecaptchaSiteKey(config('easyforms.form.google_recaptcha.site_key'))
        ->setName('ExampleForm')
        ->setTitle('This is an example form.');
}

Managing the Minimum Score

The minimum score cannot currently be applied per form. This is done on a global scale and can be set withing the easyforms config file. It is currently set to 0.5 but can be updated for any value between 0.0 and 1.0

php
'minimum_score' => 0.5,
'minimum_score' => 0.5,