Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
411 views
in Technique[技术] by (71.8m points)

parameters - Codeigniter passing 2 arguments to callback

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)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...