WordPress.org

Ready to get started?Download WordPress

Forums

Handling validation/input errors on Widget update (3 posts)

  1. Tom Auger
    Member
    Posted 3 years ago #

    I'm looking to the community to point me to examples of best practices or conventions around handling invalid user input on widget update.

    As an example, suppose in my widget form, I have a field labelled "Number of posts", and the user either enters some text, or a number that is out of range. In the update method of the widget, I can easily check and then just use the default value if the input is invalid.

    But by itself, this isn't good UX practice - we need to let the user know that his input was invalid, and possibly why. At the very least I'd like to show an error message - somewhere.

    Is there a convention or protocol for doing this? How does update() communicate with form() to let form() know it needs to post an error message? Or does update() post the error message. And where?

    Thanks in advance!

    tom

    PS: yes, of course we can prevent the user entering the wrong info with JS validation or pull-down menus. But that's not what this question is about. My example is deliberately simple.

  2. esmi
    Forum Moderator
    Posted 3 years ago #

  3. Tom Auger
    Member
    Posted 3 years ago #

    I know this post well, but no, it does not address this issue at all. Hadlock's example does not do any error handling. It simply passes back the old instance values if the new instance values are invalid, with no use message whatsoever.

Topic Closed

This topic has been closed to new replies.

About this Topic