0

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?

3
  • no you dont need to use ajax. Commented Feb 8, 2016 at 21:09
  • Also if you don't mind refreshing the page, the isset post submit will look for an object with the name submit on it, so add name="submit" to your input submit on the form Commented Feb 8, 2016 at 21:09
  • thats not the whole function code? because its missing the basics function quick_post(){ ... Commented Feb 8, 2016 at 21:09

2 Answers 2

1

This line is searching for an object with the name submit on it

if(isset($_POST['submit']))
{

But your form doesn't have such object, so add a name to your input and the function shall work:

<input type="submit" name="submit" value="Post" class="col-md-2" id="quick-post-submit">
Sign up to request clarification or add additional context in comments.

Comments

1
<input type="submit" value="Post" class="col-md-2" id="quick-post-submit">

vs

if(isset($_POST['submit']))
{
   quick_post();
}

you didn't give the submit button a name="submit" attribute

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.