Welcome Guest, Not a member yet? Register   Sign In
Form Validation callbacks are not being called.
#1

[eluser]bennyhill[/eluser]
First, I'm NOT using HMVC or Modular extensions. I have simple validation that is running in my model and works except the callbacks are not being executed.

Code:
function create()
{
  $this->form_validation->set_rules('title', 'Title', 'trim|required|max_length[25]');
  $this->form_validation->set_rules('url', 'URL', 'required|callback_video_check');

  
  if ($this->form_validation->run() == FALSE)
  {
   return FALSE;
  }
  else
  {
   return TRUE;
   }
}

function video_check($str)
{
  $this->form_validation->set_message('video_check', 'Only YouTube Videos Are Accepted At This Time');
  return FALSE;
}

I am returning false no matter what just to test if it works. But the form still passes validation. Any thoughts? I googled and saw a lot of people have this problem but there doesn't seem to be any solutions. I even tried copying the example from the CI docs exactly and still it doesn't work.
#2

[eluser]CroNiX[/eluser]
You are loading form validation somewhere?
#3

[eluser]bennyhill[/eluser]
Auto loading in the autoload.php. All my validation like 'required' and such works so the form_validation library is loaded.
#4

[eluser]CroNiX[/eluser]
That looks like it should be fine.
You can always extend the form validation library with your own rules and then they don't become callbacks, to see if that works.

Just create:
/application/libraries/MY_Form_validation.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Form_validation extends CI_Form_validation
{
  function __construct()
  {
    parent::__construct();
  }

  function video_check($str)
  {
    $this->set_message('video_check', 'Only YouTube Videos Are Accepted At This Time');
    return FALSE;
  }
}
Then just call the rule like a native CI rule
Code:
$this->form_validation->set_rules('url', 'URL', 'required|video_check');
#5

[eluser]bennyhill[/eluser]
That worked man thanks a million!
#6

[eluser]bennyhill[/eluser]
Spoke too soon. It worked for that form. But other forms with validation that load the validations rules via /application/config/form_validation.php (as stated in the documentation) breaks. As soon as I delete /application/libraries/MY_Form_validation.php my forms work again.




Theme © iAndrew 2016 - Forum software by © MyBB