How do I create a custom form in the account area?
To create a form you need to create a class that extends the \Aero\AccountArea\AccountAreaForm class:
- The
$sectionsarray lists the views used to render the form. - The
method()method defines the method that the form will use (this should bepost,get,put, ordelete). - The
route()method should return the URL for the form.- A
$datavariable is accessible in case the route requires parameters that are available in the data.
- A
For example, here's how the login form is defined:
class LoginForm extends \Aero\AccountArea\AccountAreaForm
{
protected $sections = [
'email' => 'account-area::partials.email-input',
'password' => 'account-area::partials.password-input',
'forgot-password' => 'account-area::partials.login-forgot-password-link',
'submit' => 'account-area::partials.login-button',
];
protected function method(): string
{
return 'post';
}
protected function route($data): string
{
return route('login');
}
}
Don't forget to register your form:
\Aero\AccountArea\AccountArea::registerForm(MyForm::class);