我是wordpress的新手,我刚创建了我的第一个插件。这个插件包含一个表单。每当我让jQuery AJAX Post Request
提交表单时,我都会在警告框中收到此错误。
Call to undefined function add_shortcode() in <b>J:\xampp\htdocs\wordpress\wp-content\plugins\auc_result_fetcher\includes\search.php</b> on line <b>22</b><br />
我正在使用Wordpress 3.8.1
。 add_shortcode()
函数在我想要显示的任何地方成功显示表单。但每当我发出jQuery AJAX Post Request
时,我都会收到上述错误消息。
修改
我的代码段。
add_action('init', function() {
add_shortcode('search_form', 'print_search_form');
});
add_action('init', 'fetch_grades');
add_action('init', 'fetch_search_options');
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="POST" action="">
<table>
<tr>
<td style="text-align:right;"> <span>Class:</span> </td>
<td><select id="select-class" name="search-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" name="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>
</div>
<?php
}
请帮帮我。谢谢。