Problem using form validation with custom form fields

edited July 2012 in Modules
I'm using a custom form field (there is no field for it in the modules database table).
In the modules form_fields() function I use the following code to generate my form field:
$fields['csv_import'] = array( 'type' => 'file', 'overwrite' => false, 'accept' => 'csv|txt|xls', 'order' => 1000, 'label' => 'CSV Import', 'upload_path' => TRAVEL_PORTAL_PATH.'assets/data/', 'overwrite' => TRUE //TODO: Check if file already exists //'filename' => */ );
That works perfectly fine.
I can access the uploaded file from the form in my on_after_post() function.

Now I'd like to add some validation to my field, so I changed my on_before validate($values) function like this (just for testing -> the validation rule array('no test', 'test') always returns false, so an error message should appear.)
function on_before_validate($values) { $saved_data = $this->normalized_save_data; $this->add_validation('csv_import', 'is_equal_to', 'Yehaaa!', array('no test', 'test')); return $values; }
The Code above doesn't work. I don't get a validation error message.

if I change my code to
function on_before_validate($values) { $saved_data = $this->normalized_save_data; $this->add_validation('title', 'is_equal_to', 'Yehaaa!', array('no test', 'test')); return $values; }
where 'title' is a normal form input field (the module generates out of my database table), everything works fine. -> I get a validation error.

How can I add validation rules to custom form fields?

Thanks for your help and the great CMS/Framework.
Sign In or Register to comment.