Home > CodeIgniter, Computing, Programming, php > Adding a second argument to CI form_validation callbacks

Adding a second argument to CI form_validation callbacks

About a month ago I started working with the CodeIgniter framework. It’s the first framework I have worked with and frankly, I love it!

So I was looking to add a second parameter to a form_validation callback. Here’s what I found:

$this->form_validation('user_name', 'name', "callback_test_name[$param2]");

and the callback:

test_name($name, $param2){
    ..// some logic to return
}

The form_validation class uses the form value as the first parameter, and you can pass the second parameter in the arguments as you would with any other rule references. (First snippet)

At first I was calling 2 validations. First the standard type of validation, then another validation on the same input. * BAD IDEA *

There were some issues with order of operations. I found it best to chain the whole lot together. Like so:

$this->form_validation('user_name', 'name', "required|min_length[10]|callback_test_name[$param2]");

I hope that helps anybody with the same question.

  1. July 16th, 2015 at 04:27 | #1

    Obrigado por compartilhar seus conhecimentos e por cuidar de nós… Nós todos precisamos desesperadamente disso.
    jocuriyoo​b.com | juegosyep​i.me | yoobfriv.​net | yoobgamesfriv.com
    Não devemos nos sentir culpados ou envergonhados por compartilhar e baixar arquivos digitais.

Comment pages
1 2 333
  1. No trackbacks yet.