I would like to allow my subscribers to post classifieds, which are nothing but a custom post type with a few metas for the price, etc. (The existing classifieds plugins I have tried are way too complex for my needs.) I would like to know if the following makes sense.

  • I define a [classifieds-form] shortcode displaying the form and I create a page (ie., a “page” post in the admin section) calling it.

  • The content of the form is POST’ed to another page which calls the [handle-classified] shortcode, which checks if the user is logged in, parses the $_POST data, and inserts the custom post (with a ‘pending’ status, until an admin validates it).

Does this sound reasonable to you? Or would you recommend a more “standard” way of doing this?

Thanks a lot!

1 Answer
1

Alway send submissions to the page the form is displayed. In your shortcode callback you can then display proper error or success messages.

Sample:

add_shortcode( 'classifiedsform', 'classifiedsform_callback' );

function classifiedsform_callback()
{
    if ( 'POST' !== $_SERVER['REQUEST_METHOD'] 
        or ! isset ( $_POST['classifieds'] )
    )
    {
        return classifieds_input_form();
    }

    // process input show errors or success message

}

function classifieds_input_form()
{
    // return a string with the form HTML
}

Make sure you don’t use a reserved variable or WordPress will drop the content silently.

Leave a Reply

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