• I am writing a very simple plugin that just needs a couple of configuration settings. I’m completely new to WordPress but not PHP development. Having a bit of a struggle understanding some things.

    I followed the tutorial at http://ottodestruct.com/blog/2009/wordpress-settings-api-tutorial/ which is perfectly clear and all worked as described first go.

    The problem is that I don’t really understand what the validation callback is trying to do. In my book, what’s shown here is not really validation – it’s just blanking out invalid values. Surely, there is some way of generating a helpful error message if the user makes an invalid input?

    I did a search but just seem to get pointed back to that tutorial.

    Can anybody help?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Take a look at add_settings_error() and it’s relatives.

    add_settings_error() can be used to display messages at the top, but last time I used the settings API I was also frustrated by how it would blank out values rather than (say) highlighting that field with an ‘error’ class and retaining the previously entered value so the user doesn’t have to re-enter.

    You’ll likely need to extend the settings api functionality to support that, or create your own admin page and handle things yourself using jquery validation / server-side validation / etc. Would be great if we could make that an option with the core settings api!

    Thread Starter thepurpleblob

    (@thepurpleblob)

    Thanks guys… I missed that completely and it doesn’t seem especially well documented 🙁

    It’ll probably only ever be used internally so doesn’t need to be a really polished solution. It’s more for when I forgeth what I did in 6 months time. Typing it twice won’t kill me. As a bit of an outsider it does seem a bit agricultural though…

    Moderator bcworkz

    (@bcworkz)

    “it does seem a bit agricultural though…”
    😀 😀 :D!
    Perfect description!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Settings API – confused about validation’ is closed to new replies.