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.

Can I force users to choose a category in Vanilla 2?

whu606whu606 MVP
edited July 2011 in Vanilla 1.0 Help
I've searched for this, and found workarounds which I assume only refer to Vanilla 1.

At the moment, the default category is whichever one I last used (as admin), unless, of course, the user starts a discussion from inside a category.

For forgetful members this results in odd threads appearing in non-relevant categories, and me or another mod doing housekeeping.

As for the Vanilla 1 workaround here: http://vanillaforums.org/discussion/7146

I would like to force my users to choose a category before they can post a discussion.

As always, any help gratefully received.

Thanks.
Tagged:

Best Answer

  • LincLinc Admin
    Answer ✓
    In /views/post/discussion.php (copy it from Vanilla app into your theme if you haven't yet) find this:
    echo $this->Form->DropDown('CategoryID', $this->CategoryData, array('TextField' => 'Name', 'ValueField' => 'CategoryID'));
    And replace with:
    echo $this->Form->DropDown('CategoryID', $this->CategoryData, array('IncludeNull' => TRUE, 'TextField' => 'Name', 'ValueField' => 'CategoryID'));

Answers

  • LincLinc Admin
    Answer ✓
    In /views/post/discussion.php (copy it from Vanilla app into your theme if you haven't yet) find this:
    echo $this->Form->DropDown('CategoryID', $this->CategoryData, array('TextField' => 'Name', 'ValueField' => 'CategoryID'));
    And replace with:
    echo $this->Form->DropDown('CategoryID', $this->CategoryData, array('IncludeNull' => TRUE, 'TextField' => 'Name', 'ValueField' => 'CategoryID'));
  • Thank you very much for that.

    Once again a question answered promptly and perfectly!

    My virtual hat off to you all.

    Thanks.
  • jrossjross New
    edited August 2011
    @Lincoln, - would there be a way to show a pop-up that let's people know that they didn't select a category - right now on mine the following code shows up in the pop up window:
    {"Code":8,"Exception":"Undefined index: \n\n#0
    \/home\/vc\/applications\/vanilla\/controllers\/class.postcontroller.php
    (140): Gdn_ErrorHandler()\n#1 \/home\/vc\/library\/core\/class.dispatcher.php
    (299): PostController->Discussion(Array, Array)\n#2 \/home\/vc\/index.php
    (51): Gdn_Dispatcher->Dispatch()\n#3 {main}"}
  • jross

    using the code Lincoln gave me on my site, if a user doesn't choose a Category then there is 'red box' pop-up at the top of the page 'CategoryID is required'. I haven't found how to change that message, though.
  • edited September 2011
    This would be wonderful. Is it possible to do this within the hooks code or a plugin, so I don't have to modify the base vanilla code?

    Though I would argue it should be baseline anyway - if categories are in use, it should force you to choose one.
Sign In or Register to comment.