Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
    
I don't see the need for the shortcode at all. Why not just make a custom template to show your content? –  s_ha_dum Mar 14 '13 at 18:09
    
Thanks for the comment. In fact, the idea was to implement the classifieds in a plugin rather than in the theme. But having them in a plugin is not crucial at all, and I can implement them in the theme if it makes things simpler ... –  Nown Mar 14 '13 at 18:16
    
Implementing in the theme is simpler, certainly, and should work with less overhead-- no call to process the shortcode--, but the right approach depends on what you intend for this project. Is it for your site alone? Or is it something you want to release publicly? Are you worried about changing themes? Either way, I think you should only need one shortcode, not two. –  s_ha_dum Mar 14 '13 at 18:22
    
Ok, thank you very much. In fact I intend at first to use this for my website only. But if it works properly, I was thinking of making it publicly available. I guess I'll start with a custom template, and if I want to release it someday, it should not be that hard to use a shortcode instead... –  Nown Mar 14 '13 at 18:32

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
Thank you very much! –  Nown Mar 14 '13 at 19:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.