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. November 7th, 2012 at 00:31 | #1

    Sculpting in time, but found the dry sorrow. That year, I remember this sentence: it is called time, remember
    to bring once sad. As the years passed, frozen fell in love sob intermittently. A little rain of fireworks, to conceal
    the lovesick self overflow. Don’t be silly, doomed the sigh leisurely.

  2. November 7th, 2012 at 06:01 | #2

    Currently often the concern could crop up this the reason complete ought to get such a solution? They say very simple that is certainly these kind of Wenger Wristwatches usually are robust and may also last longer in the event looked after in a very proper way.

  3. February 12th, 2013 at 20:30 | #3

    Do this come similar using php?

  4. March 2nd, 2013 at 09:08 | #4

    the subject that you wrote is very interesting and helpful

  5. March 2nd, 2013 at 09:09 | #5

    this is a very good post.Great and helpful blog

  6. March 2nd, 2013 at 09:11 | #6

    this is a very nice and helpful information. super b blog

  7. March 2nd, 2013 at 09:12 | #7

    i like your writing very much. i am impressed from your content

  8. March 13th, 2013 at 04:34 | #8

    If you doubt yourself , then indeed you stand on shaky11 ground .

  9. May 4th, 2013 at 04:14 | #9

    Thanks for taking the time to talk about this, I’m fervently about this and I appreciate studying this topic. Please, while you gain information, please update this web site with increased information. I’ve found it very helpful. There must be charging stations everywhere.

  1. No trackbacks yet.