WordPress : Front end form submit with jquery form plugin

I have used used the jquery form and tried submitting the form in wordpress but it results in error , form post value is not shown . After long reseach i got the solution about it , form data submission is cannot be done as we normally do in php. For wordpress we need to define the function in function.php of our theme and perform the desire action. I we can to use form as

<form id="myForm"action="http://mysite.com/submitest"method="post"> 
Name: <inputtype="text"name="name"/> 
Comment: <textareaname="comment"></textarea>
<inputtype="submit"value="Submit Comment" name="form_sub"/>

Then add the following code to your

add_action('init', 'form_submit');

function form_submit(){
        //here you'll have your form data in a $_POST array, you can check it using a print_r. parse the form and insert the post
        $title = $_POST['name'];
        $content = $_POST['comment'];

        //change the category and author as you want
        $post_obj = array(
                        'post_title' => $title,
                        'post_content' => $content,
                        'post_category' => array(1), //Uncategorized
                        'post_status' => 'draft',
                        'post_author' => 1 //Admin
        $id = wp_insert_post($post_obj);

        //check if successfully submitted
        if(isset($id) && !is_wp_error($id))
            //redirect to a thank you page, make sure the slug is 'thank-you'
Source : http://wordpress.stackexchange.com/questions/33896/front-end-submit-form-with-jquery-form-plugin

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.