05-22-2008, 08:12 AM
[eluser]abmcr[/eluser]
I have a problem if i want to set a callback as rules....
in my controller i have this code
And the callback not work... Why?
Another small bug: the Select all link in the display mode not work...
[quote author="jTaby" date="1211413715"]abmcr, you want $this->CI->codexadmin->rules....codexadmin is a library in the CI object[/quote]
ok .... i have made this small feature for get a rule required indicator as in attached image
in the codexforms.php librarie insert this function
after, in each plugin where you want the symbol change the lines in
Finally, insert into the css a .required class.
I have a problem if i want to set a callback as rules....
in my controller i have this code
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
include("codexcontroller.php");
class Example extends codexController
{
function Example ()
{
// Load the CodexController
codexController::codexController();
$rules['textbox_test'] = "trim|required|callback_username_check";
$config = array(
'db_table' => 'example', //The name of the table associated with this controller
'form_setup' => $this->spyc->YAMLLOAD($this->codexadmin->getDefinitionFileName('example_form')), //The array that holds our elements
'controller_name' => 'Example', //The name of the controller, so that it can be used when generating the URLs
'primary_key' => 'my_id', //The name of the controller, so that it can be used when generating the URLs
'display_fields'=>array('textbox_test','date_test','related_example'),
'rules'=>$rules
);
$this->setConfig($config);
}
function username_check($str)
{
if ($str == 'test')
{
$this->validation->set_message('username_check', 'The %s field can not be the word "test"');
return FALSE;
}
else
{
return TRUE;
}
}
}
?>
And the callback not work... Why?
Another small bug: the Select all link in the display mode not work...
[quote author="jTaby" date="1211413715"]abmcr, you want $this->CI->codexadmin->rules....codexadmin is a library in the CI object[/quote]
ok .... i have made this small feature for get a rule required indicator as in attached image
in the codexforms.php librarie insert this function
Code:
/*
* The function create a * symbol for a field with a rule required
*/
function required($field){
$this->CI = &get;_instance();
$required=NULL;
if (isset($this->CI->codexadmin->rules)){
if (array_key_exists($field,$this->CI->codexadmin->rules)) {
//search if a rule is 'required' in the rules
$rules=explode("|",$this->CI->codexadmin->rules[$field]);
$required=((in_array("required", $rules))?"<span class='required'>*</span>":NULL);
}
}
return $required;
}
after, in each plugin where you want the symbol change the lines
Code:
$html .= '
<label for="'.$this->element_name.'">
'.$this->label.'
</label>';
Code:
$html .= '
<label for="'.$this->element_name.'">
'.$this->label.$this->required($this->name).'
</label>';