In Codeigniter, how do I pass the third parameter for a callback (form validation)?

I am currently using a form validation class (on Codeigniter) and customization rules.

It works as follows with two parameters ( codeigniter.com/user_guide/libraries/form_validation.html ):

$this->form_validation->set_rules('username', 'Username', 'callback_test[abc]'); 

But what about the third parameter? And the fourth ...? Is it possible?

+6
source share
5 answers

This is not official, but it works

Divide parameter by ','

 $this->form_validation->set_rules('article_big_image','Gambar Besar','callback_check_picture[article_big_image,edit]'); function check_picture($image,$param){ $param = preg_split('/,/', $param); $field = $param[0]; $action = $param[1]; echo $field.$action; } 
+12
source

Not without an extended system form validation class. For information on how to achieve this, check out the article.

Alternatively, you can access post variables in your callback function using:

 $this->input->post('field_name'); 

which may or may not help you.

0
source

You can use Array to get additional parameters for more fields, as shown below:

  $error = array( array( 'field' => 'check', // the field name will come here 'label' => 'Check', 'rules' => 'required|here you can put the callback Function' ) ); 
0
source
 $this->form_validation->set_rules('article_big_image','Gambar','callback_check_picture[article_big_image,edit]'); function check_picture($image,$param){ $param = explode(',', $param); $field = isset($param[0])?$param[0]:''; $action = isset($param[1])?$param[1]:''; echo $field.$action; } 
-1
source

You can go to the rule |callback_handle_is_unique_value_combinations[val1,val2]

than, public function callback_handle_is_unique_value_combinations($str, $field) { $fields = explode(',', $field); $val1 = $fields[0]; $val2 = $fields[1]; public function callback_handle_is_unique_value_combinations($str, $field) { $fields = explode(',', $field); $val1 = $fields[0]; $val2 = $fields[1];

and then you made your cponarisons

-2
source

Source: https://habr.com/ru/post/905184/


All Articles