After posting a form having two fields named 'id' and 'url' I have the following code:
$this->load->library('form_validation'); $this->form_validation->set_rules('id', 'id', 'trim|xss_clean'); $this->form_validation->set_rules('url', 'url|id', 'trim|xss_clean|callback_url_check');
A db query needs both fields.
The function url_check($str, $id) is called but in this case 'id' always has the value 0.
If I just do :
$this->form_validation->set_rules('url', 'url', 'trim|xss_clean|callback_url_check');
And call url_check($str)
everything's working as it's is supposed to do.
The question is how do I pass two values to the url_check($str, $id)
?
You can use $this->input->post directly:
function check_url() { $url = $this->input->post('url'); $id = $this->input->post('id'); // do some database things you need to do e.g. if ($url_check = $this->user_model->check_url($url, $id) { return TRUE; } $this->form_validation->set_message('Url check is invalid'); return FALSE; }
Just do it the right way (at least for CI 2.1+) as described in the docs:
$this->form_validation->set_rules('uri', 'URI', 'callback_check_uri['.$this->input->post('id').']'); // Later: function check_uri($field, $id){ // your callback code here }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With