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.

Disable the Body is required message.

smoigecomsmoigecom New
edited January 2011 in Vanilla 2.0 - 2.8
Hi,

I want the body of the post to be optional. How can this be accomplished?

Thank you.
Tagged:
«1

Comments

  • MarkMark Vanilla Staff
    You may have to edit the core for this one. We never dreamed that anyone would want to be able to post blank messages. Care to give us some insight into why you need this?
  • A title is enough for what I need. Maybe a user can get his whole idea across with just a few words, and being forced to write a description isn't necessary.
  • edited January 2011
    Maybe you could hook into the model and if the body is blank before validation then change the body to:   and the post will appear with just a space in it (pretty much blank).

    This could also be done with some javascript by binding to the submit event and checking if the form is empty.

    This is definitely a very hacky way round and editing the core to remove one line would probably be the way forward :)
  • Any code examples would be very helpful for me .. i m a little lost in Vanilla. Thank you.
  • edited January 2011
    @smoigecom

    In applications/vanilla/models/class.discussionmodel.php
    go to line 516: $this->Validation->ApplyRule('Body', 'Required');

    and comment it out:
    // $this->Validation->ApplyRule('Body', 'Required');
  • smoigecomsmoigecom New
    edited January 2011
    thank you for your help. I am using the mobile theme (figured I should mention that)

    // Add & apply any extra validation rules:
    $this->Validation->ApplyRule('Body', 'Required');
    $MaxCommentLength = Gdn::Config('Vanilla.Comment.MaxLength');
    if (is_numeric($MaxCommentLength) && $MaxCommentLength > 0) {
    $this->Validation->SetSchemaProperty('Body', 'Length', $MaxCommentLength);
    $this->Validation->ApplyRule('Body', 'Length');
    }

    I found the code that you were talking about ... but commenting out the body required doesn't do anything. I still get the Body is required message. Any other thoughts?
  • Would need to comment out the body length rule as well, but i will have a play later on. Didn't test it at all, just for discussions posts right? and not comments.
  • Yup ... when somebody wants to post something, I would just like the body to be optional. Thank you for your help. I just tried commenting out the body length ... but I get the same thing ... weird.
  • any help on this one ... anybody
  • edited January 2011
    @smoigecom Okay i have a fix:
    You still need to comment out the Body required thing above $this->Validation->ApplyRule('Body', 'Required'); (you dont need to comment out the length ones).

    And then all you have to do now is:
    Go to applications/vanilla/settings/structure.php Line 53:\
    Change
    ->Column('Body', 'text', FALSE, 'fulltext')
    To
    ->Column('Body', 'text', TRUE, 'fulltext')

    Then just disable and re-enabled vanilla from the dashboard.
  • smoigecomsmoigecom New
    edited January 2011
    I m not sure what happened, but after I did what you said, I tried to disable vanilla and then this happened

    Fatal error: Class 'CategoryModel' not found in /home/content/c/i/p/cip6791/html/_domains/smoige.com/plugins/Categories2Menu/class.categories2menu.plugin.php on line 80

    I had problems with the File Upload plugin as well. It was giving me the same problem. After deleting plugin folders and uploading them back ... i got the forum to work in a way. I can do anything, but visit a post. I get the Bonk message. What should I do? Reinstall? I ll leave it the way it is for now, maybe you can help me figure out what is wrong. I would really want to keep everything I have and still use Vanilla.
    Thank you.
  • edited January 2011
    @smoigecom First things first, upgrade to the latest vanilla. This will remove any changes you made above anyways. Then once it is working again, try the edit above again. If you want you can private message me on here.
  • Ok ... so the whole thing got screwed up. It's my fault. Can I reinstall Vanilla and then point it to the old database?
  • Make a backup if the database first and then yes. Make sure to run the upgrade script.
  • Oh so I should install the previous version and then make an upgrade? What if I just install the new version, and then just edit the conf settings? Won't that work?
  • Yeah, that's what I meant use the new version. But you will have to run the utility/upgrade script on it.
  • Hi,

    I know this is an old thread but I'd like to do the same thing (make Body be optional) for the same reason -- but without modifying core files.

    @garymandell mentioned you might be able to hook in to the form and substitute an empty body for a body with an empty space character. I tried that but no success yet. Here's the code:

    public function DiscussionModel_BeforeSaveDiscussion_Handler($Sender) {
        if ($Sender->EventArguments['Discussion']->Body == '') {
            $Sender->EventArguments['Discussion']->Body = 'A programmatically substituted body';
        }
      }
    

    But this doesn't work -- it still says "Body is required".

    Any ideas?

    Thanks,
    David

  • R_JR_J Ex-Fanboy Munich Admin

    When the event "BeforeSaveDiscussion" is fired, there is no such thing as a discussion, so it couldn't be (and isn't) passed in the EventArguments. Instead all you at this point in time are some form values. So your code should look like that:

    public function DiscussionModel_BeforeSaveDiscussion_Handler($Sender) {
       if ($Sender->EventArguments['FormPostValues']['Body'] == '') {
          $Sender->EventArguments['FormPostValues']['Body'] = 'A programmatically substituted body';
       }
    }
    

    Do you mind sharing why an empty body is needed? Just curious...

  • hgtonighthgtonight ∞ · New Moderator
    edited March 2015

    @davidnhutch

    Create a plugin that modifies the structure of the discussion and comment table to make the body column nullable. That will remove the requirement from the schema automatically:

    public function Structure() {
        $Structure = Gdn::Structure();
        $Structure->Table('Discussion')
                ->Column('Body', 'text', TRUE, 'fulltext')
                ->Set();
        $Structure->Table('Comment')
                ->Column('Body', 'text', TRUE, 'fulltext')
                ->Set();
    }
    
    public function Setup() {
        $this->Structure();
    }
    

    When enabled, this plugin should remove the requirement.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • R_JR_J Ex-Fanboy Munich Admin

    @hgtonight: are you sure? DiscussionModel has that code:

       public function Save($FormPostValues) {
          $Session = Gdn::Session();
    
          // Define the primary key in this model's table.
          $this->DefineSchema();
    
          // Add & apply any extra validation rules:
          $this->Validation->ApplyRule('Body', 'Required');
    ...
    

    So I'd say independently from the scheme, the "Required" validation will happen.

Sign In or Register to comment.