[eluser]Unknown[/eluser]
Hello,
this simply extension may be useful when you handling multiple database connections. Put this in your private library folder.
Code:
<?php
class MY_Form_validation extends CI_Form_validation {
function __construct($config = array()) {
parent::__construct($config);
}
/**
* Is_unique check
*
* Returns boolean
*
* @return bool
*/
public function is_unique($str, $field) {
list($db, $table, $field) = explode('.', $field);
$query = $this->CI->$db->limit(1)->get_where($table, array($field => $str));
return $query->num_rows() === 0;
}
}
now you can use in your config something like this:
Code:
$config = array(
'radius/add' => array(
array(
'field' => 'nasname',
'label' => 'lang:radius_ipaddress',
'rules' => 'required|valid_ip|is_unique[dbobject.tablename.tablefield]' // accepts now the database object
),
array(
'field' => 'shortname',
'label' => 'lang:radius_shortname',
'rules' => 'callback_validate_domain'
),
array(
'field' => 'key',
'label' => 'lang:radius_secret',
'rules' => 'required|alpha_numeric'
),
array(
'field' => 'description',
'label' => 'lang:radius_description',
'rules' => 'min_length[10]'
),
),
Regards,
Patrick