我有以下代码,它应该在页面上创建一个表单,当我提交它时,它应该连接到数据库并将日期和表单信息添加到wp_user_feedback。目前表格甚至没有出现在页面上,不确定为什么?
新错误:
Notice: Undefined index: responseFields in /Users/anderskitson/Sites/fiftyfity/wp-content/themes/fiftyfityNew/contact-form
第33行的copy.php
<?php function make_user_feedback_form() {
global $wpdb;
global $current_user;
$ufUserID = $current_user->ID;
$ufResponses = serialize($_POST["responseFields"]);
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'updateFeedback' ) {
$ufDataUpdate = $wpdb->insert( 'wp_user_feedback', array( 'date' => current_time('mysql'), 'responses' => $ufResponses ) );
}?>
<ol>
<form method="post">
<li>Question 01<br /><input type="text" id="responseFields[]" value="" /></li>
<li>Question 02<br /><input type="text" id="responseFields[]" value="" /></li>
<li><input name="submit" type="submit" id="submit" class="submit button" value="Send feedback" /></li>
<?php wp_nonce_field( 'updateFeedback' ); ?>
<input name="action" type="hidden" id="action" value="updateFeedback" />
</form>
</ol>
<?php
}
add_action('the_content','make_user_feedback_form');
?>
答案 0 :(得分:1)
你在函数中有表单。你在任何地方调用这个函数吗?
如果您不打算将其作为该功能的一部分,请将最后}
移至开头<ol>
所以,它应该看起来像这样(如果把它拉出函数)
<?php function make_user_feedback_form() {
global $wpdb;
global $current_user;
$ufUserID = $current_user->ID;
$ufResponses = serialize($_POST["responseFields"]);
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'updateFeedback' ) {
$ufDataUpdate = $wpdb->insert( 'wp_user_feedback', array( 'date' => current_time('mysql'), 'responses' => $ufResponses ) );
}
}
?>
<ol>
<form method="post">
<li>Question 01<br /><input type="text" id="responseFields[]" value="" /></li>
<li>Question 02<br /><input type="text" id="responseFields[]" value="" /></li>
<li><input name="submit" type="submit" id="submit" class="submit button" value="Send feedback" /></li>
<?php wp_nonce_field( 'updateFeedback' ); ?>
<input name="action" type="hidden" id="action" value="updateFeedback" />
</form>
</ol>
<?php
add_action('the_content','make_user_feedback_form');
?>