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.

Forcing users to choose a category

whu606whu606 I'm not a SuperHero; I just like wearing tights... MVP
edited November 2011 in Vanilla 2.0 - 2.8
My original question was answered most helpfully by Lincoln here:

http://vanillaforums.org/discussion/16672/can-i-force-users-to-choose-a-category-in-vanilla-2#Item_6

but this fix no longer works with the latest version of Vanilla.
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'));
The new line is slightly different:

echo $this->Form->CategoryDropDown('CategoryID', array('Value' => GetValue('CategoryID', $this->Category)));

Lincoln's fix meant that users had to explicitly choose a category, and was very helpful for our site.

Could someone tell me how to alter the new code (assuming it is possible).

Cheers as always to anyone who can help.
Tagged:

Best Answer

  • ToddTodd Chief Product Officer Vanilla Staff
    Answer ✓
    It looks like 2.0.18 doesn't easily support this hack.

Answers

  • ToddTodd Chief Product Officer Vanilla Staff
    I think you want:
    echo $this->Form->CategoryDropDown('CategoryID', array('IncludeNull' => TRUE, 'Value' => GetValue('CategoryID', $this->Category)));
  • whu606whu606 I'm not a SuperHero; I just like wearing tights... MVP
    Todd

    thanks for your quick reply.

    I edited the line to the one you suggested, but it doesn't seem to have any effect.

    Previously, the category box was empty, and the user couldn't post until they had explicitly chosen a category.

    Thanks.
  • ToddTodd Chief Product Officer Vanilla Staff
    Answer ✓
    It looks like 2.0.18 doesn't easily support this hack.
  • whu606whu606 I'm not a SuperHero; I just like wearing tights... MVP
    edited November 2011
    OK

    No worries.

    It was useful because it stopped users leaving the category on the default one.

    They'll just have to get used to changing it!

    Thanks.
  • whu606whu606 I'm not a SuperHero; I just like wearing tights... MVP

    Update, in case this gets found by a search in the future...

    Just discovered that the code Todd supplied works provided that the Categories option is NOT set to 'Display root categories as headings.'

Sign In or Register to comment.