Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to do some form validation on my custom meta box, and I remember somewhere reading about some javascript function to disable/enable the Publish button - except I can't find it.

How do I either

a) enable/disable the publish button or,

b) when Publish is clicked, trap it and prevent the update and alert the user, but in such a way that it can be updated later

I've tried just a simple click handler with e.preventDefault() and e.stopPropagation however the swily icon comes up and the button stays disabled because it never finishes

Thanks

share|improve this question

2 Answers 2

Rather than trying to interfere with the button operation and doing validation in jQuery or javascript, I find it easier to hook the save_post action and do my validation in php (checking if certain post_meta exist or are correct), then if things don't check out, you can set the post status back to "pending", which in effect overrides the Publish button. The page simply loads back up (having been saved), but they have to correct their errors before "publishing" can be done.

share|improve this answer

I'm using jquery tools validator

   $("#publish").click(function(event){


       //validating
       var inputs = $(".TTWForm-container :input").validator();

       //check if not valid stop loading ajax icons
       if( ! inputs.data("validator").checkValidity()){

           event.stopImmediatePropagation();

       }

this code fired once publish botton clicked then checks if the form is valid or not if it is not it stop all events propagation which shows the ajax loading icons and so otherwise it works without a problem

long time via the question asked but posting it for who is googling it.

share|improve this answer
    
Why reinvent the wheel with jQuery, when WordPress already provides hooks - i.e. save_post, draft_post - into which to hook meta box validation callbacks? –  Chip Bennett Feb 20 '12 at 21:33
1  
No wheel reinventing here it is a matter of building responsive Ajax validation on the time let it be a box that is required is n't it better to validate it in time and tell the user to add it either than making a request to the server and decide if the input is ok or not ? –  Atef Apr 6 '12 at 15:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.