Using shortcodes to parse POST request (containing the data from a front-end form)

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.

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

Thanks a lot!

Related posts

Leave a Reply

1 comment

  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.