So I have looked around online and found some questions on here about it, but nothing seemed to work for my situation.
I have a form which should call a function that is set on the page.
The form's html is as follows:
<form method="post" action="">
<textarea id="input-box" placeholder="What's on your mind?" maxlength="10000" name="quick-post-area" class="col-md-offset-2 col-md-6"></textarea>
<input type="submit" value="Post" class="col-md-2" id="quick-post-submit">
</form>
and the function:
// Initialize the page ID to -1. This indicates no action has been taken.
$post_id = -1;
$author_id = 1;
$slug = 'post';
global $current_user;
// If the page doesn't already exist, then create it
if( null == get_page_by_title( $title ) ) {
// Set the post ID so that we know the post was created successfully
$pollq_question = wp_kses_post( trim( $_POST['pollq_question'] ) );
$post_id = wp_insert_post(
array(
'comment_status' => 'open',
'ping_status' => 'closed',
'post_author' => $current_user->ID,
'post_name' => $slug,
'post_title' => 'Posted By:' . $current_user->ID,
'post_status' => 'publish',
'post_type' => 'post',
'post_content' => $_POST['quick-post-area']
)
);
// Otherwise, we'll stop
} else {
// Arbitrarily use -2 to indicate that the page with the title already exists
$post_id = -2;
} // end if
} // end programmatically_create_post
and finally the isset that I am trying to use to call the function:
if(isset($_POST['submit']))
{
quick_post();
}
Anyone got any ideas about what I need to change for it to fire?
isset post submitwill look for an object with the namesubmiton it, so addname="submit"to your input submit on the formfunction quick_post(){ ...