Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter

Categories

In this Discussion

Who's Online 8

CurtisOdenericgillettefh111sarowlwptc74 +3 guests

Forcing users to choose a category

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:

Comments

  • Posts: 1,586
    I think you want:
    echo $this->Form->CategoryDropDown('CategoryID', array('IncludeNull' => TRUE, 'Value' => GetValue('CategoryID', $this->Category)));

    Vanilla co-founder

  • Posts: 346
    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.
  • Posts: 1,586 Accepted Answer
    It looks like 2.0.18 doesn't easily support this hack.

    Vanilla co-founder

  • Posts: 346
    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.
  • Posts: 346

    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.