Skip to content

Feature suggestion: Form & input blocks #44186

@aristath

Description

@aristath

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:

  1. 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
  2. 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 and label.

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

Related: #21443, #30754

Metadata

Metadata

Assignees

No one assigned

    Labels

    New BlockSuggestion for a new block[Type] DiscussionFor issues that are high-level and not yet ready to implement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions