CodeIgniter Forums

Full Version: Strange callback function behaviour with Modular Extensions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Wayne Smallman[/eluser]
Having just wired up the callback validation for Modular Extensions, I'm seeing something very strange.

First, here's the field:

Code:
array(
'field' => 'snippet',
'label' => "Snippet",
'rules' => 'trim|required|callback_convert_characters'
)

Here's the callback function:

Code:
public function convert_characters ($string) {
  if (!$this->ion_auth->logged_in()):
   redirect('users/login/');
  else:
   if (isset($string)):
    echo "Yes!";
    // For reference: www.ascii-code.com
    return str_replace(
     array("'", "'", '"', '"', '-', '--', '...'),
     array("\xe2\x80\x98", "\xe2\x80\x99", "\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x80\xa6"),
     $string
    );
   else:
    $this->form_validation->set_message('convert_characters', "The ‘%s’ field doesn't contain text.");
    return false;
   endif;
  endif;
}

Ignore the actual logic, as it's in progress, which — incidentally — isn't doing what it should be, perhaps because of this error I'm seeing.

Instead, take a look at the echo and the validation error message. When I edit the item to which this code validates, both the echo and the error trigger.

Yes, the string is present, which I've echoed out, just to be sure.

Any ideas?

Hi, could someone please delete this topic? I've found a different method of doing what I need to do.