Skip to:
Content
Pages
Categories
Search
Top
Bottom

Form to forum


  • brandysve
    Participant

    @brandysve

    Hi !

    I have a website with bbpress and I want than when user fill a form (I can do it myself or by a form plugin) it create a new post with the element of the form (like name and message).

    Any idea?

    Thank you !

Viewing 8 replies - 1 through 8 (of 8 total)

  • Barry
    Participant

    @barryhughes-1

    There is of course the [bbp-topic-form] shortcode that ships with bbPress itself … but if that’s unsuitable or if customizing it to meet your goals isn’t an option for any reason, then you could roll your own solution quite easily.

    Here is a (super simple) example of just that – it creates an extremely simple (single field!) form via the [post_to_bbp] shortcode and uses the submitted data to create a new forum topic. Of course, there is a great deal it doesn’t do that you’d probably want in place before using it in production, but it’s just an example after all 🙂


    brandysve
    Participant

    @brandysve

    Thank you, I’ll look at this as soon as I can and i’ll come back 🙂


    brandysve
    Participant

    @brandysve

    Hi ! I want to know. Is it possible to display the URL of the new forum post when the user click on submit? (Thank for you subscription, you can see your post here : + URL)


    Barry
    Participant

    @barryhughes-1

    I’m sure you could do that pretty easily.

    If a call to bbp_insert_topic() is successful it returns the post ID of the newly created topic. You can in turn pass that to get_permalink() which will provide you with the URL.

    get_permalink()


    brandysve
    Participant

    @brandysve

    Ho, how can I return the post ID of the newly created Topic?


    Barry
    Participant

    @barryhughes-1

    Well, if you’re building on my example code you could make a few changes in order to get the information flowing back to the success message:

    # Find this line
    bbp_insert_topic( /* ... */ );
    
    # Change it: let's catch the post ID
    $topic_id = bbp_insert_topic( /* ... */ );
    
    # Find this line
    post_to_bbp_status( 'success' );
    
    # Change it: let's pass the post ID instead of 'success'
    post_to_bbp_status( $topic_id );
    
    # Find this condition
    if ( 'success' === post_to_bbp_status() )
    
    # Change it: test to see if it contains a post ID
    if ( is_numeric( post_to_bbp_status() ) )
    
    # Find the line
    return 'Thank you for your submission.';
    
    # Change it: display the new topic's permalink
    return 'Check your post: ' . get_permalink( post_to_bbp_status() );

    Note that these changes are untested, they don’t do any safety checks etc etc. However, I hope it gives you some ideas you can use to further develop your own solution 🙂


    brandysve
    Participant

    @brandysve

    Hi ! That help me a lot, one last thing. I don’t receive notifications by mail of the new created topic. Any idea?


    Barry
    Participant

    @barryhughes-1

    Notifications would normally be dispatched when the bbp_new_topic action fires.

    In this case, you’d either have to trigger that manually or else call bbp_notify_forum_subscribers() directly (or else craft a manual solution of your own).

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Skip to toolbar