Skip to content

Instantly share code, notes, and snippets.

@christopherarter
Last active October 1, 2015 13:10
Show Gist options
  • Save christopherarter/4bec4b550bf90fcfde07 to your computer and use it in GitHub Desktop.
Save christopherarter/4bec4b550bf90fcfde07 to your computer and use it in GitHub Desktop.
Trying to add comment
<form action="" id="new_comment" name="new_comment" method="POST">
<textarea rows="3" cols="50" id="commentContent" name="commentContent" placeholder="Type notes about this APU" name="commentContent"></textarea>
<button type="submit" style="float:right; margin:10px;"><i class="fa fa-comments fa-lg" style="margin-right:10px;"></i> Add Note</button>
</form>';
// END FORM HTML
/* Comment Form PHP */
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "new_game_post") {
// Validate the field to ensure it isn't empty.
if (isset ($_POST['commentContent'])) {
$comment = $_POST['commentContent'];
} else {
echo 'Please enter a note';
}
// Add the content of the form to $post as an array
$new_comment = array(
'comment_content' => $comment,
'comment_author' => get_current_user_id()
);
//insert comment
wp_insert_comment($new_comment);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment