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.

Adding a blank.. item to dropdown?

VazVaz New
edited May 2007 in Vanilla 1.0 Help
Hi guys,
I'd like to add a blank dropdown item to the dropdown menu that appears when you start a new discussion


If you notice currently there's many categories. Sometimes users when they have alot of things on there mind forget to select the correct category.

I wanted to add a blank item so that there posting fails and they go back and correct it by selecting the correct one. How do I add this blank item to the top of the dropdown menu.

I'd like the label to be a line like: ----------------------------------------------

Thanks in advance.


  • Options
    edited May 2007
    Must choose a category... # 4.

    You actually need to go a bit further down than line 208 since the core file gotten bigger since I posted that. Also, use an IF statement like suggested a few posts later. Maybe I will get around to extensionizing this eventually.

    Little more discussion of this technique here.
  • Options
    VazVaz New
    edited May 2007
    I've just integrated the change and it works great :). However, is there a way of perhaps sending the user some sort of a message or sending him back to the form with the writing still there but with a message saying 'please select'.

    Not Found
    The requested URL /forums/discussion/hello/ was not found on this server.
    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
    comes up.

    (anybody should realise by now that something went wrong on the previous page but just for those slow learners..)

    Also in the below code, what purpose does the if statement serve?

    For those reading this solution is:

    Add the following : -

    if (ForceIncomingString('CategoryID', '') == '') {
    $cs->AddOption('', 'Please select a category:');

    in /Library/Vanilla/Vanilla.Control.DiscussionForm.php, just below line 208 (inside GetDiscussionForm, just before the while loop):
  • Options
    edited May 2007
    The if statement basically checks to see if the user is already browsing a category when posting. It assumes the user will post in the category they were browsing instead of putting the invalid category option in.

    error message screenshotYou shouldn't be getting a 404 or such... it should be a message that says that you must select a valid category, with all input preserved... exactly the same as if you left the topic or body blank.

    Instead of line 208, it should be at or about 210... before the while, but after the $cs = $this->Context->ObjectFactory->NewObject($this->Context, 'Select');
  • Options
    VazVaz New
    edited May 2007
    I'm also using the friendly urls thing. It sometimes goes a little crazy when it takes time to post. It's not really an issue.

    function GetDiscussionForm($Discussion) {
    $this->DelegateParameters['Discussion'] = &$Discussion;

    if (!$this->DiscussionFormattedForDisplay) $Discussion->FormatPropertiesForDisplay();

    // Load the category selector
    $cm = $this->Context->ObjectFactory->NewContextObject($this->Context, 'CategoryManager');
    $CategoryData = $cm->GetCategories(0, 1);
    $cs = $this->Context->ObjectFactory->NewObject($this->Context, 'Select');
    $cs->Name = 'CategoryID';
    $cs->CssClass = 'CategorySelect';
    $cs->SelectedValue = ForceIncomingInt('CategoryID', $Discussion->CategoryID);
    $cat = $this->Context->ObjectFactory->NewObject($this->Context, 'Category');
    $LastBlocked = -1;
    if (ForceIncomingString('CategoryID', '') == '') {
    $cs->AddOption('', 'Please select a category:');

    while ($Row = $this->Context->Database->GetRow($CategoryData)) {
    if ($cat->Blocked != $LastBlocked && $LastBlocked != -1) {
    $cs->AddOption("-1", "---", " disabled=\"true\"");
    $cs->AddOption($cat->CategoryID, $cat->Name);
    $LastBlocked = $cat->Blocked;
  • Options
    That looks perfect.

    hmm... never tested with Friendly URLs, but don't see how that could be a problem... will have to try it out sometime.

    Maybe after I finish this vBulletin migrator thingy ;-)
  • Options
    OH MY GAAD! *extra big smile*
This discussion has been closed.