Widget Validation
-
I am having some trouble figuring out what I need to do to get some validation code to work and return validation errors in a widget’s admin area.
I have made a couple of widgets extending wp_widget, all of which work fine, however when I have gone to add fairly standard validation code to the widget I am not having much luck.
I put the validation code (the validation code I am talking about is no sanitisation but validation – ie – does a certain piece of data contain certain characters only or a certain number of characters) into the update method (function) and it works up to a point.
The error messages display when and if the fields have been filled in incorrectly. However the error message is also appearing when I first pull the widget into a sidebar.
I am having trouble getting the widget to either not save/update immediately it is pulled into a sidebar area and also not run the error check or to work out how to distinguish between a new widget use and an admin user has already tried to update. I have tried to do this with jquery but I believe that the ajax code wordpress is already using to deal with a save is interfering with my own code. At any rate I would prefer to do the checks using php.
Perhaps I have gone about this the wrong way and there is a more “official” way to handle errors specifically or otherwise in the admin settings/options for a widget.
Any help and/or suggestions would be much appreciated.
- The topic ‘Widget Validation’ is closed to new replies.