Skip to content

Meta boxes: server side validation with add_settings_error isn't possible #3964

Closed

Description

Issue Overview

A lot of existing meta boxes, especially in enterprise environments, rely on server side validation / sanitation, including meaningful feedback to the user.

This fails in Gutenberg currently.

Steps to Reproduce (for bugs)

  1. Setup validation as in https://tommcfarlin.com/post-meta-data-error-messages/ , this requires a CPT 'Location' and a meta box with a single text field.

  2. Create a new location, fill in data and save it.

  3. API Call will fail with an error "Call to undefined function add_settings_error()", which is used in the example

  4. Replace add_settings_error() with a simple string to continue testing.
    https://gist.github.com/wsydney76/0dd717fd061908d8037d29ce12569b86

  5. Enter a value and save.

  6. Then leave the text field blank and save. "Post saved" indicates ok, no error messages shown, the field is still blank.

  7. Reload. The old field value is still present.

  8. Enter content like 'with tags and save. Tags will be stripped server side, but that is not reflected in the editor. Only a reload shows the altered content.

Gutenberg 1.9

Expected Behavior

The user has to get information about the data being rejected or changed server side. After a "successful" update the content in the editor must not differ from the content in the database.

Current Behavior

If it works at all, the users workflow is broken, potentially resulting in invalid data.

Possible Solution

Documentation is needed:

  • Which kind of implementations of server side validation breaks in Gutenberg?
  • How can it be changed to work in Gutenberg?

Activity

  1. added
    Backwards CompatibilityIssues or PRs that impact backwards compatability
    [Type] Plugin InteroperabilityIncompatibilities between a specific plugin and the block editor. Close with workaround notes.
    on Mar 30, 2018
  2. danielbachhuber commented on Mar 30, 2018

    @danielbachhuber
    Member

    Related #5590

    API Call will fail with an error "Call to undefined function add_settings_error()", which is used in the example

    @wsydney76 Can you clarify what you mean by this?

  3. danielbachhuber commented on Apr 4, 2018

    @danielbachhuber
    Member

    Created #5975 to define a formal notices API.

  4. added this to the milestone on May 21, 2018
  5. danielbachhuber commented on Aug 22, 2018

    @danielbachhuber
    Member

    In thinking through this further, I'm not sure it will be possible to support this formally in Gutenberg.

    We could potentially detect calls to add_settings_error() in the POST request to save meta boxes. However, there's no formal API between calls to add_settings_error() and their display, so I'm not sure what Gutenberg would do if it detected these calls. Reloading the meta box part of the page would be insufficient, because admin_notices is in the header of the page.

    With this being said, someone could produce a plugin implementation that replicates the validation behavior, and we could refer to that as a recommended compatibility shim. I'm not sure Gutenberg could do something like this correctly by default, but a workflow where the user has to install and test the plugin would also verify the validation works for them as expected.

  6. mcsf commented on Aug 30, 2018

    @mcsf
    Contributor

    Came here via #4063. @danielbachhuber, I noticed you self-assigned this one. Out of your curiosity, what's your plan here?

  7. danielbachhuber commented on Aug 30, 2018

    @danielbachhuber
    Member

    Out of your curiosity, what's your plan here?

    Document and close, most likely.

  8. removed this from the Merge: Back Compat milestone on Oct 3, 2018
  9. added this to the WordPress 5.0 milestone on Oct 3, 2018
  10. removed their assignment
    on Oct 17, 2018
  11. 4 remaining items

  12. changed the title [-]Meta boxes: server side validation fails[/-] [+]Meta boxes: server side validation with `add_settings_error` fails[/+] on Nov 6, 2018
  13. changed the title [-]Meta boxes: server side validation with `add_settings_error` fails[/-] [+]Meta boxes: server side validation with `add_settings_error` isn't possible[/+] on Nov 6, 2018
  14. ryanwelcher commented on Feb 7, 2023

    @ryanwelcher
    Contributor

    Is this issue still relevant?

  15. ndiego commented on May 25, 2023

    @ndiego
    Member

    This issue was reviewed in today's Documentation Issue Scrub. Given the inactivity of this issue in the last couple of years, I am going to close. However, if anyone feels like this should be reopened, please don't hesitate to do so. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Backwards CompatibilityIssues or PRs that impact backwards compatabilityNeeds Technical FeedbackNeeds testing from a developer perspective.[Feature] Meta BoxesA draggable box shown on the post editing screen[Priority] LowUsed to indicate that the issue at hand isn't a top priority to address and can be handled later[Type] Developer DocumentationDocumentation for developers[Type] Plugin InteroperabilityIncompatibilities between a specific plugin and the block editor. Close with workaround notes.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions