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
Hello,
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";
$dm->SaveDiscussion($dis);
Could you please help me? Maybe, there's already a function doing this?
Thanks.
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";
$dm->SaveDiscussion($dis);
Could you please help me? Maybe, there's already a function doing this?
Thanks.
0
This discussion has been closed.
Comments
- 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" . '" ');