Reputation: 6110
I have the following code, which is supposed to create a form on the page, and when I submit it it should connect to the database and add the date and form info to wp_user_feedback. Currently the form doesn't even show up on the page not sure why?
NEW ERROR:
Notice: Undefined index: responseFields in /Users/anderskitson/Sites/fiftyfity/wp-content/themes/fiftyfityNew/contact-form
copy.php on line 33
<?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');
?>
Upvotes: 0
Views: 1527
Reputation: 6389
You have the form in the function. Are you calling the function anywhere?
If you didn't intend it to be part of the function, move the last }
above the opening <ol>
So, it should look like this (if pulling it out of the function)
<?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');
?>
Upvotes: 1