Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在wordpress插件中处理表单?_Php_Wordpress_Forms_Plugins - Fatal编程技术网

Php 如何在wordpress插件中处理表单?

Php 如何在wordpress插件中处理表单?,php,wordpress,forms,plugins,Php,Wordpress,Forms,Plugins,在我的插件中,我想处理发布的表单数据。“我的表单输入”按钮如下所示: <form action="<?php echo plugins_url('plugin_directory/my-plugin.php'); ?>"method="post"> <input type="submit" name="button1" class="button1" id="button1" value="button 1"> </form> 但是w

在我的插件中,我想处理发布的表单数据。“我的表单输入”按钮如下所示:

<form action="<?php  echo plugins_url('plugin_directory/my-plugin.php'); ?>"method="post">  
   <input type="submit" name="button1" class="button1" id="button1" value="button 1">
</form>
但是wordpress和插件脚本之间似乎存在一些冲突,因为我遇到了以下错误:“调用未定义的函数add_action()

那么如何正确处理wordpress插件中的表单呢?表单操作重定向正确,但无法再次执行脚本。我还尝试了表单action=“#”和从浏览器复制的绝对URL路径。此时将显示页面,但不显示表单if语句


有人知道怎么做吗?

只需在插件文件中加载wp-load.php,然后就可以使用添加操作了

if (isset($_POST['button1'])) {
    $file=plugins_url('file_1.txt');
    var_dump('button clicked');
}
elseif(isset($_POST['button2'])){
    $file=plugins_url('file_2.txt');
}
...
else {
$file=plugins_url('file_1.txt');//default value of variable when no button is clicked    
}