I have a plugin that adds meta boxes to the admin interface and I need to do some validation when the user presses the "update" button before the form is submitted.
Is there a WordPress action or hook to add my function to the form's onsubmit? Or do I need to simply do this:
Pseudo code
var myInput = document.getElementById( "myMetaBoxInput" );
//Get form from input
var form = myInput.form;
//They have something already set
if ( form.onsubmit )
{
var previousSubmit = form.onsubmit;
form.onsubmit = function() {
//do my code....
//Call their function
previousSubmit();
}
} else form.onsubmit = myfunction;
The problem with doing the above is that it's possible that wordpress could have some code that happens on the "update" button's "click" action which will set the form's onsubmit
to another function and clear mine out.