RSS

Monthly Archives: June 2014

Passing Multiple Parameters to Form Validation Custom Callbacks in Codeigniter

Codeigniter Custom Callbacks

Codeigniter Custom Callbacks

CI natively only allows for  single parameter in custom callbacks. For an instance see the following code.

$this->form_validation->set_rules
('hstate', 'State', 'required|callback_suburb_check[' . $suburb . ']');

If you need to pass multiple parameters, you have several options. Obviously you can change CI behaviour by subclassing the core library. But in this tutorial we follow the less pain approach. That ‘s to access required parameters via POST variables within your custom callback function. They are still available in this scope.

There is another way using your PHP string handling knowledge. Just formatting all the parameters as single string and passing to the callback function.

$parameters = 'first_arg' . '||' . 'second_arg' . '||' . 'third_arg';
$this->form_validation->set_rules
('some_field', 'Some Field Name', 'callback__my_callback_function['.$parameters.']');  

Then in your callback,

function _my_callback_function($field_value, $second_parameter){
    list($first_param, $second_param, $third_param) = split('||', $second_parameter);
    ...
}
 
Leave a comment

Posted by on June 30, 2014 in Codeigniter

 

Tags: ,

How to check HTML5 Web Storage Support in JavaScript?

HTML5 Data Storage

HTML5 Data Storage

function supports_html5_storage() {
                try {
                    return 'sessionStorage' in window && window['sessionStorage'] !== null;
                } catch (e) {
                    return false;
                }
            }
            alert(supports_html5_storage());
 
2 Comments

Posted by on June 26, 2014 in HTML5

 

Tags: ,