Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Automatically create a new discussion

edited October 2008 in Vanilla 1.0 Help

I've integrated Vanilla with my website. I'd like to create a new Vanilla discussions using PHP. I believe it's quite easy, unfortunately I can't find the way to do it.
In my PHP code, I have a string for the body and a string for the discussion title, how to post it? The user is already logged in.

I tried the following, but I think a few things are missing:

$dis = $Context->ObjectFactory->NewContextObject($Context, 'Discussion');
$dis->Comment = $Context->ObjectFactory->NewContextObject($Context, 'Comment');
$dm = $Context->ObjectFactory->NewContextObject($Context, 'DiscussionManager');
$dis->Name = "Discussion title";
$dis->Comment->Body = "Message body";

Could you please help me? Maybe, there's already a function doing this?



  • Options
    When I had a similar goal some time ago, what I had done was:
    - in my code create a form with only hidden field in it, these fields should reflect those defined by the core, especially "FormPostBackKey" which authenticate the post.
    - then on some user action, post this form to the Vanilla core at "/post.php" and let Vanilla do the job.

    Here below is an excerpt from my code. It use a special syntax of no use for anyone beside listing relevant fields and their value.

    $form_discussion->define_controls(' "DiscussionID", \'input(array("type"=>"hidden","id"=>$id,"value"=>0))\' "CommentID", \'input(array("type"=>"hidden","id"=>$id,"value"=>0))\' "AuthUserID", \'input(array("type"=>"hidden","id"=>$id,"value"=>0))\' "UserDiscussionCount", \'input(array("type"=>"hidden","id"=>$id,"value"=>0))\' "WhisperUsername", \'input(array("type"=>"hidden","id"=>$id,"value"=>""))\' "PostBackAction", \'input(array("type"=>"hidden","id"=>$id,"value"=>"SaveDiscussion"))\' "FormatType", \'input(array("type"=>"hidden","id"=>$id,"value"=>"Html"))\' "CategoryID", \'input(array("type"=>"hidden","id"=>$id,"value"=>"'. $B_config['categorie_livres'] .'"))\' "FormPostBackKey", \'input(array("type"=>"hidden","id"=>$id,"value"=>"'. session_val('SessionPostBackKey') .'"))\' "Body", \'input(array("type"=>"hidden","id"=>$id))\', "","' . "This is the default first comment body" . '" "Name", \'input(array("type"=>"hidden","id"=>$id))\', "", "' . "This is Discussion title" . '" "discussion", \'input(array("type"=>"submit","id"=>$id))\',"","' . "Create a Discussion" . '" ');
  • Options
    Thanks, I'll try this. I don't think I've got a "$form_discussion" variable, but I'll search.
  • Options
    No $form_discussion is a private variable of my own. Don't look at it neither try to get the syntax of this snippet. Only relevant and useful are the fields names and the value for "FormPostBackKey" from the session element "SessionPostBackKey"
This discussion has been closed.