2
votes

I am trying to validate custom meta box fields. On the server side I tried to use "return false" on the "save_post" action, but WP disregards it (apparently the save_post is called after the post is already inserted to the DB). I then resorted to JQuery on the client-side, but using "return false" froze the page, and it stopped responding, as if I was using an infinite loop.

the code is plain and simple:

         $("#post").submit(function(){
         if ($("input[name='post_title']").val()==='') {return false;};
         });

Any ideas? Maybe built-in WP functionality?

1
Could you post the jQuery code? :D - Stephen Harris

1 Answers

1
votes

The WordPress SE site has some good stuff on this topic..

Server side validation is obviously preferable.. can't rely on javascript.

This topic has a good discussion on how WP lets you handle errors.

I haven't tried implementing anything like this on meta boxes, so I can't say for sure it'll solve your problem, but hopefully it will put you on the right track.