Php 无法在WordPress插件创建中的函数内获取$\u POST super全局数组的值
我是wordpress的新手,我正在尝试创建一个简单的插件,将数据插入并获取到mysql数据库中。当我想访问我的Php 无法在WordPress插件创建中的函数内获取$\u POST super全局数组的值,php,mysql,wordpress,post,Php,Mysql,Wordpress,Post,我是wordpress的新手,我正在尝试创建一个简单的插件,将数据插入并获取到mysql数据库中。当我想访问我的PHP函数中的超级全局$\u POST数组时,就会出现问题。如果在我的PHP函数之外使用print\r($\u POST)函数,我可以看到通过$\u POST数组传递的值。但是如果我尝试在函数中使用print\r($\u POST),它将不显示任何内容 我正在使用jquerypostajax请求提交表单 我想访问我的PHP函数中的$\u POST数组query mysql,从数据库中获
PHP函数
中的超级全局$\u POST
数组时,就会出现问题。如果在我的PHP函数
之外使用print\r($\u POST)
函数,我可以看到通过$\u POST
数组传递的值。但是如果我尝试在函数中使用print\r($\u POST)
,它将不显示任何内容
我正在使用jquerypostajax
请求提交表单
我想访问我的PHP函数中的$\u POST
数组
query mysql,从数据库中获取数据,并在需要时从函数返回结果
我的插件的目录结构如下所示
auc_result_fetcher //this is the main plugin folder
auc_result_fetcher.php // This file includes other scripts using include function
includes // directory containing other files to be included
fetch.php // this file contains the functions to fetch data from mysql db
scripts.php // this file contains the enqueue code of js and css scripts
search.php // this file contains form to submit data and also displays it
js //directory contsins js files
auc-custom-jquery.js
css //directory contsins css files
auc-custom-stylesheet.css
auc\u result\u fetcher.php包含以下代码
/*plugin header information goes here..*/
/************
AUC Constants
*************/
define("PAGE_URI", plugins_url());
define("SEARCH_RESULTS", PAGE_URI."/auc_result_fetcher/includes/fetch.php/");
/************
AUC Includes
*************/
include ("includes/scripts.php");
include ("includes/fetch.php");
include ("includes/search.php");
add_action('init', function() {
add_shortcode('search_form', 'print_search_form');
});
add_action('init', 'fetch_grades');
add_action('init', 'fetch_search_options');
add_action('init', 'fetch_student_results');
function print_search_form(){
?>
<div class="auc-search-form">
<div id="error">
<div id="select-class-error"></div>
<div id="select-search-by-error"></div>
<div id="search-field-error"></div>
</div>
<form id="searchForm" method="get" action="">
<table>
<tr>
<td style="text-align:right;"> <span>Class:</span> </td>
<td>
<select id="select-class">
<option>Select Class</option>
<?php
$grades = fetch_grades();
foreach($grades AS $v){
echo "<option>".$v->grade_title."</option>";
}
?>
</select>
</td>
<td id="class-select"></td>
</tr>
<tr id="previous-row">
<td style="text-align:right;"> <span>Search By:</span> </td>
<td>
<select id="search-by">
<option>Select Choice</option>
<?php
$grades = fetch_search_options();
foreach($grades AS $v){
echo "<option>".$v->search_title."</option>";
}
?>
</select>
</td>
</tr>
<tr id="search-row">
<td id="search-by-option-label" style="text-align:right;"><span></span></td>
<td id="search-by-field"><input type="text" name="searchBy" id="search" /></td>
</tr>
<tr >
<td ></td>
<td>
<input type="hidden" id="url" name="url" value="<?php echo SEARCH_RESULTS; ?>">
<input type="button" id="search-button" value="Search" />
<input type="reset" name="searchBy" id="reset" value="Cancel"/>
</td>
</tr>
</table>
</form>
<table id="results-table">
<tr>
<th>Roll Number</th>
<th>Name</th>
<th>School</th>
<th>Class</th>
</tr>
<?php
fetch_student_results();
/*echo "<pre>";
print_r($d);
echo "</pre>";*/
?>
</table>
</div>
<?php
}
$(document).ready(function(){
var selectCls = $("select#select-class").val();
var searchBy = $("select#search-by").val();
var searchField = $("input#search").val();
var url = $("input#url").val();
$.post(url, {c: selectCls, s: searchBy, f: searchField}, function(data){
alert(data);
});
});
$data = $_POST;
$result = do_something($data);
function do_something($data){
// Do something with the $data and return result
}
search.php包含此代码
/*plugin header information goes here..*/
/************
AUC Constants
*************/
define("PAGE_URI", plugins_url());
define("SEARCH_RESULTS", PAGE_URI."/auc_result_fetcher/includes/fetch.php/");
/************
AUC Includes
*************/
include ("includes/scripts.php");
include ("includes/fetch.php");
include ("includes/search.php");
add_action('init', function() {
add_shortcode('search_form', 'print_search_form');
});
add_action('init', 'fetch_grades');
add_action('init', 'fetch_search_options');
add_action('init', 'fetch_student_results');
function print_search_form(){
?>
<div class="auc-search-form">
<div id="error">
<div id="select-class-error"></div>
<div id="select-search-by-error"></div>
<div id="search-field-error"></div>
</div>
<form id="searchForm" method="get" action="">
<table>
<tr>
<td style="text-align:right;"> <span>Class:</span> </td>
<td>
<select id="select-class">
<option>Select Class</option>
<?php
$grades = fetch_grades();
foreach($grades AS $v){
echo "<option>".$v->grade_title."</option>";
}
?>
</select>
</td>
<td id="class-select"></td>
</tr>
<tr id="previous-row">
<td style="text-align:right;"> <span>Search By:</span> </td>
<td>
<select id="search-by">
<option>Select Choice</option>
<?php
$grades = fetch_search_options();
foreach($grades AS $v){
echo "<option>".$v->search_title."</option>";
}
?>
</select>
</td>
</tr>
<tr id="search-row">
<td id="search-by-option-label" style="text-align:right;"><span></span></td>
<td id="search-by-field"><input type="text" name="searchBy" id="search" /></td>
</tr>
<tr >
<td ></td>
<td>
<input type="hidden" id="url" name="url" value="<?php echo SEARCH_RESULTS; ?>">
<input type="button" id="search-button" value="Search" />
<input type="reset" name="searchBy" id="reset" value="Cancel"/>
</td>
</tr>
</table>
</form>
<table id="results-table">
<tr>
<th>Roll Number</th>
<th>Name</th>
<th>School</th>
<th>Class</th>
</tr>
<?php
fetch_student_results();
/*echo "<pre>";
print_r($d);
echo "</pre>";*/
?>
</table>
</div>
<?php
}
$(document).ready(function(){
var selectCls = $("select#select-class").val();
var searchBy = $("select#search-by").val();
var searchField = $("input#search").val();
var url = $("input#url").val();
$.post(url, {c: selectCls, s: searchBy, f: searchField}, function(data){
alert(data);
});
});
$data = $_POST;
$result = do_something($data);
function do_something($data){
// Do something with the $data and return result
}
编辑:请看一下我的详细代码,这样你就可以了解发生了什么
请帮助我如何实现这一目标。这种行为似乎是wordpress特有的。请帮我做这个。提前谢谢 对不起,把问题读快一点 好的,那么您正在将表单提交到例如
myfile.php
在myfile.php中
您可以进行打印($\u POST)。如果是,则:
@Rebbeca希望使用ajax而不是$post wordpress data post数据访问表单的发布数据。我已经发布了我的代码。请看一看.ajax调用,使用apache的错误日志进行调试,我会使用错误日志(print_r($_POST,true));我还使用了
error\u log(print\r($\u POST,true))代码>并且它也不起作用。