Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Posting a new discussion with data from a form

Hi everyone! I'm super new to the Vanilla scene so forgive me in advance if this is a simple topic and is answered elsewhere.

I am working something where it utilizes Vanilla for the forum. Something was recently requested and I'm not sure how to go about it. I've spent about a week searching for the right answers. I'm using Vanilla 2.1.8p2 and it looks like the API route was the way to go, but unfortunately it doesn't work with anything < 2.2.x.

Let me tell you a bit about what is being asked of me. Basically, this is what is requested:
* Users fill out a form on the main website (not forum)
* Their information is taken and placed as a new discussion in a category with special permissions.
* The user who posted it is a special user made only for these sorts of interactions (for example, the username can be "MyWebsite.com").

My questions:
* Is it possible to have code that will log in as that user (MyWebsite.com) only to post this new discussion? I was originally looking at jsConnect but it doesn't seem that it would be able to achieve what I am looking for (although it is possible that I could have misread the information)
* Is there a special term for this that I may be missing? Are there any examples out there?
* I looked in the database and it appears that the GDN_Discussion table holds this information. While I prefer to avoid directly modifying the DB, is this the only way to achieve my goal?

Thanks in advance! I don't require super detailed answers if it is explained somewhere else ( a link would be handy! ) but if you can help point me in the right direction, it would be very helpful.

Comments

  • Options
    R_JR_J Ex-Fanboy Munich Admin
    edited February 2015

    I have no experienc with jsConnect, but I bet it is capable of what you are trying to achieve. If not, you can load the framework from your main site and use the code in this plugin as an example on how to create a discussion

  • Options

    I'm looking into this now. I didn't know you could load the framework like that. That's a big help! Thanks!

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    While thinking about that, it seems to me that this is probably not the best solution...

    Do you use another framework for your main site? And are the ones who submit a form logged in users? Use JsConnect to authentify the user and write a plugin that is only accessible for logged in users which does the discussion creation.
    Having two frameworks loaded for one simple submit form sounds not wise.

    You do not use another framework? Create your form with Vanilla! That's really easy. And a page provided by Vanilla doesn't need to look like a Vanilla page. It should be quite easy to simply reuse what you have right now.
    Loading Vanilla after the form has been submitted is possible, but it would be more elegant to let Vanilla do the form handling. That's what a framework is good at.

  • Options

    If he wants to use an external form though, directly inserting a discussion into the database should work.

    That's also how the embedded comments create the initial discussion post:
    https://github.com/vanilla/vanilla/blob/2.1/applications/vanilla/controllers/class.postcontroller.php#L432-L460

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    Inserting into db skips all plugins and built in functionality. Even notifications will not work and that's the same for all plugins that use e.g. DiscussionModel_BeforeSave.

  • Options

    @R_J said:
    Inserting into db skips all plugins and built in functionality. Even notifications will not work and that's the same for all plugins that use e.g. DiscussionModel_BeforeSave.

    You're right. DiscussionModel->Save is better.

  • Options

    My site uses drupal just for the ease of posting articles for administrators, but end users wont be logging in from here. The only log in functionality we have is in the forums. I ended up spending some time inside the postcontroller file last night but need to spend some more time with it. I did notice that file is where discussions were created.

    I couldnt get that framework to work (might be a php config error.. not entirely sure) but I will try again later tonight. Thanks for your replies!

Sign In or Register to comment.