class SampleFormFieldset extends Fieldset {
function __construct() {
$this->validation()->add_callable('CustomValidation');
$this->add('field_1', 'Field 1')->add_rule('custom');
$this->add('field_2', 'Field 2');
}
}
class CustomValidation {
function _validation_custom($val) {
// I'd like to check the value of field_2 here.
// Ex. if the value of field 1 is 1, then 2 must be 1, and if the value of field 1 is 2, then field 2 must be 4, etc.
}
}
class SampleController {
function action_sample() {
$form = new SampleFormFieldset();
$val = $form->validation();
if(Input::method() == 'POST' && Security::check_token() && $val->run()) {
// do something
}
}
}
class SampleFormFieldset extends Fieldset {
function __construct() {
$this->validation(CustomValidation::forge($this)); // this sets the extended validation object used for this validation
$this->add('field_1', 'Field 1')->add_rule('custom', 'field_2');
$this->add('field_2', 'Field 2');
}
}
class CustomValidation extends Validation {
function _validation_custom($val, $field_name) {
$field_value = $this->input($field_name);
// Use $field_value
}
}
It looks like you're new here. If you want to get involved, click one of these buttons!