views:

209

answers:

2

I'm not sure how I should phrase this, so pardon me for my lack of narrative..

Here's an approximate form of my current code, trimmed down to the essentials of the problem (PHP v5.2 / CodeIgniter v1.7):

In system/application/config/form_validation.php, I have a rule that looks like this:

'some_controller/save' => array(
    array(
        'field' => 'some_code',
        'label' => 'Some Code Name',
        'rules' => 'trim|required|min_length[1]|max_length[6]|callback__unique_codename'
    ),
),

In system/application/controllers/some_controller.php, I have the custom callback function needed by the above validation rule:

function _unique_codename($codename)
{
    $result = $this->some_code_model->find_by_codename($codename); // this returns NULL if the codename is not found
    if ($result)
    {
        $this->form_validation->set_message('_unique_codename', '%s already exists. Please enter another %s.');
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}

After form submission and an error occurs, the message displayed is: "Some Code Name already exists. Please enter another ."

Is there any way to evaluate multiple "%s" instances in the error message?

A: 

you're running _unique_codename only on the some_code field right? if thats the case, what do you mean by multiple instances of %s?

do you want to run this in a loop and collect all the errors to be displayed at the same time?

stef
I guess I simplified the example to much.Abnormal cases would include:* using the same custom callback function for different fields* having additional parameters passed to the custom callback function, like: `'rules' => 'trim|required|callback__unique_codename[some_other_field]'`
Nikki Erwin Ramirez
A: 

I would recommend downloading 1.7.2 from the SVN. It fixes several bugs regarding the form_validation class.

Zack