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.

Add validation with no model - is it possible?

csakipcsakip New
edited August 2012 in Vanilla 2.0 - 2.8

I'm creating a plugin to add extra input fields to the new discussion dialog form.
I use PostController_BeforeBodyInput_Handler to add the controls to the form. They display fine.

However I can't add validation to these elements. The data in them are custom set so they are not in the models that the PostController use. Is it possible to add validation to them?

I couldn't find an event to make custom validation either. I can't stop the save action on invalid data. I can only get the form data on the PostController_AfterDiscussionSave_Handler but at that place the discussion is already saved.


  • Options
    SS ✭✭
    edited August 2012

    Use BeforeSaveDiscussion.

       public function DiscussionModel_BeforeSaveDiscussion_Handler($DiscussionModel) {
            $Validation = $DiscussionModel->Validation;
            $Validation->AddRule('CoolRule', 'function:ValidateCoolRule');
            $Validation->ApplyRule('CoolFieldName', 'CoolRule');

    Out of class:

    if (!function_exists('ValidateCoolRule')) {
        function ValidateCoolRule($Value, $Field = '', $PostValues = False) {
            if ($Value == '1') return TRUE;
            return '%s: Incorrect value.'; // %s - CoolFieldName
            // return FALSE;
  • Options

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    BeforeSaveDiscussion did the trick.
    Thank you.

Sign In or Register to comment.