-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
What problem does this address?
Most sites need forms in one form or the other.
We already have the comment form, but that covers a very specific and limited scenario - leaving comments on a post.
This still leaves contact/feedback etc forms, and is one of the things that a huge number of sites needs.
Yes, there are plugins out there that do forms, but this is such a fundamental feature that we should have the building blocks for a form as part of Core.
What is your proposed solution?
I suggest creating 2 new blocks:
- A "Form" block. This will be the wrapper element for forms, adding the
<form>
element and allowing users to nest blocks inside it. It should have an area for inner blocks, and a submit button at the bottom - An "Input" block. This block will only be visible/available when the parent block is a form block. In its most basic and initial implementation, it should have 2 attributes:
type
andlabel
.
A simplified example of the generated HTML should look like this:
<form>
<p>This is a paragraph block with <a href="https://example.com">a link etc</a>.</p>
<label>
This is the label for a field
<input type="text">
</label>
<input type="submit" value="Submit">
</form>
The default action for the form should be to simply send an email to the site-admin.
We can have a PHP filter on the block's render callback to change the action - which will allow us to reuse the form for everything else we need (comment form, login block etc), as well as allow 3rd-party blocks & plugins to build forms in a unified and consistent way, and do what they need to do with the form's actions.
This will also help us abstract and improve existing blocks:
- Comment form
- Login form