We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Module Form Validation Callbacks

Development and Programming

ab92012's avatar
ab92012
2 posts
11 years ago
ab92012's avatar ab92012

Hi

I am creating a module within Expression Engine 2, which utilises the form validation class processed via template tags, however when I attempt to use a callback validation rule no method is called.

Are callback validation rules supported in Expression Engine and if so could someone point me to a successful example?

Thanks

       
Jonathan's avatar
Jonathan
2 posts
10 years ago
Jonathan's avatar Jonathan

Yes. If you look at the EE_Form_validation.php you will see this

/**
  * Sets additional object to check callbacks against such as fieldtypes
  * to allow third-party fieldtypes to validate their settings forms
  *
  * @param object  Fieldtype to check callbacks against
  * @return void
  */
 public function set_fieldtype($fieldtype)
 {
  $this->_fieldtype = $fieldtype;
 }

Here is an example usage:

public function submit() {
        ...
        ee()->form_validation->set_fieldtype($this);
        ee()->form_validation->set_rules('field_x', lang('field_x'), 'required|callback_field_x_check');
        ...
    }

    public function field_x_check() {
        // Validate
        return TRUE;
    }

Refer to the Codeigniter Form Validation docs for more details on how to use the callback validation.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.