This is a simple package for the HTML Forms plugin that allows you to easily render forms using a corresponding Blade view (if one is present) with Sage 10.
A few additional opinionated tweaks include:
- Moving the HTML Forms admin menu item to the Options submenu.
- Hide the ads shown in the sidebar of the admin page.
- Sage >= 10.0
- HTML Forms
- PHP >= 7.3
- Composer
Install via Composer:
$ composer require log1x/sage-html-forms
Start by creating a form in the HTML Forms admin menu page if you do not already have one.
You can leave the "Form code" blank as it will not be used if a corresponding Blade view exists.
Once your form is created, simply generate a view using the slug assigned to your form:
$ wp acorn make:form contact-us
You will find the generated form view in resources/views/forms/contact-us.blade.php
containing a simple form component:
<x-html-forms :form="$form" class="my-form">
<input
name="name"
type="text"
placeholder="Full Name"
required
>
<input
name="emailAddress"
type="email"
placeholder="Email Address"
required
>
<input
type="submit"
value="Submit"
/>
</x-html-forms>
When HTML Forms processes "Form Actions" – it simply fetches each input name to create the usable variables.
That being said, the default view would provide [NAME]
and [EMAILADDRESS]
.
Outside of defining your error messages on the options page, you can optionally provide them to the <x-html-forms />
component directly:
<x-html-forms
:form="$form"
:messages="['success' => 'Thank you!', 'error' => 'Yikes! Try again.']"
class="my-form"
/>
By default the HTML Forms menu items is moved to the Options submenu. Prevent that by using the hf_hide_admin_menu
hook:
add_filter('hf_hide_admin_menu', '__return_false');
If you discover a bug in Sage HTML Forms, please open an issue.
Contributing whether it be through PRs, reporting an issue, or suggesting an idea is encouraged and appreciated.
Sage HTML Forms is provided under the MIT License.