WordPress 元框\自定义字段验证
我正在尝试验证自定义元框字段。在服务器端,我尝试在“save_post”操作上使用“return false”,但 WP 忽略它(显然在帖子已插入数据库后调用 save_post)。 然后我在客户端求助于 JQuery,但使用“return false”冻结了页面,并且它停止响应,就像我使用了无限循环一样。
代码简单明了:
$("#post").submit(function(){
if ($("input[name='post_title']").val()==='') {return false;};
});
有什么想法吗?也许内置 WP 功能?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WordPress SE 网站有一些关于这个主题的好东西。
服务器端验证显然更可取。不能依赖 javascript。
本主题很好地讨论了 WP 如何让你处理错误。
我还没有尝试在元盒上实现类似的东西,所以我不能肯定地说它会解决你的问题,但希望它会让你走上正确的轨道。
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.