简体   繁体   English

如何在自定义插件中以WordPress自定义形式添加验证

[英]How to add validation in WordPress custom form in custom plugin

I've made a custom form and made a custom plugin of it to send email and store data into database, everything is working fine. 我已经制作了一个自定义表格,并为其制作了一个自定义插件,用于发送电子邮件并将数据存储到数据库中,一切正常。 I am using PHP mailer for sending email & using SQL query for storing data into my database table but issue is: after every two minutes it is keep sending empty Email to my mail address and keep storing empty fields into my database. 我正在使用PHP邮件发送器发送电子邮件,并使用SQL查询将数据存储到数据库表中,但问题是:每两分钟,它将不断向我的邮件地址发送空的电子邮件,并继续将空字段存储到我的数据库中。

I've used isset empty validation but it is not working here which prevents from storing empty data into database in PHP but not working in WordPress using custom plugin. 我使用过isset空验证,但是它在这里不起作用,这阻止了将空数据存储到PHP中的数据库中,但是无法使用自定义插件在WordPress中工作。

if(isset($_POST) & !empty($_POST)){
$name = $_POST['name'];
 if(!isset($name) || empty($name)){
 $error[] = "Name is required";
 }

I am new in WordPress just started working here, please tell me how to prevent from storing empty fields into database or which validation/function should I use to prevent empty data fields in WordPress. 我是WordPress的新手,刚刚在这里开始工作,请告诉我如何防止将空字段存储到数据库中,或者应该使用哪种验证/功能来防止WordPress中的空数据字段。

I miss multiple things here, HTML form not posted also missing alot of functional things like how you submit this form. 我在这里错过了很多事情,没有发布HTML表单,也缺少了很多功能性的东西,例如您如何提交此表单。 My opinion is that this question is not very clear. 我认为这个问题不是很清楚。

Why your datafields are not stored? 为什么不存储您的数据字段? Are you sending empty forms or does this have to be attached to core function, provide more code so we can understand it. 您要发送空白表格还是必须将其附加到核心功能中,请提供更多代码以便我们理解。

You also really should check the docs of wordpress, especially this one for updating db records https://codex.wordpress.org/Validating_Sanitizing_and_Escaping_User_Data 您还应该检查wordpress的文档,尤其是用于更新db记录的文档https://codex.wordpress.org/Validating_Sanitizing_and_Escaping_User_Data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM