duan6161 2018-10-04 06:28
浏览 110

如何在自定义插件中添加WordPress自定义表单中的验证

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.

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.

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.

  • 写回答

1条回答 默认 最新

  • dtsnx44260 2018-10-04 07:47
    关注

    I miss multiple things here, HTML form not posted also missing alot of functional things like how you submit this form. 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

    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容