⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

How to use the post data in the validation rules?



shum
  • profile picture
  • Member

Posted 16 October 2012 - 16:11 PM

This code does not work:

$this->temp_validate = array();//global var for validation
function hard_validation($str, $param)
{
list($table, $field) = explode('.', $param);

if ( ...... hard validation $post_array['field1'], $post_array['field2'], $post_array['field3'], $post_array['field4'] .....) {
......
return true;
}
else {
$this->form_validation->set_message('hard_validation', 'My Error Message');
return false;
}
}
function callback_validation_slug($post_array, $primary_key) {

//save post in global va
if (isset($primary_key)) {
$this->temp_validate["id"] = $primary_key;
}
else {
if (isset($post_array['id'])) {
$this->temp_validate["id"] = $post_array['id'];
}
else {
// insert object, id not set
}
}
$this->temp_validate["field1"] = $post_array['field1'];
$this->temp_validate["field2"] = $post_array['field2'];
$this->temp_validate["field3"] = $post_array['field3'];
$this->temp_validate["field4"] = $post_array['field4'];
return $post_array;
}
function my_table()
{
$table = __FUNCTION__;
$this->crud->set_table($table);
....
$this->crud->set_rules("slug","MyFieldName","required|slug|min_length[3]|callback_hard_validation[$table.slug]");
$this->crud->callback_before_update(array($this, "callback_validation_slug"));
$this->crud->callback_before_insert(array($this, "callback_validation_slug"));
.....
}

What to do?
[color=#282828][font=helvetica, arial, sans-serif]Best Regards.[/font][/color]