Welcome Guest, Not a member yet? Register   Sign In
[solved] help me find why its not calling callback emailcheck function in form validation
#1

[eluser]SPeed_FANat1c[/eluser]
I have such function, in both cases now returs false, for testing.



Code:
function emailcheck($str)
    {
        if ($str == 'test')
        {
            $this->form_validation->set_message('emaiLcheck', 'The %s field can not be the word "test"');
            return FALSE;
        }
        else
        {
            return FALSE;
        }
    }

and in another file there is
Code:
array('field' => 'elpastas',
                            'label' => 'lang:elpastas',
                            //'rules' => 'trim|required|valid_email',
                            'rules' => 'callback_emailcheck',
                            'error' => 'elpastasblogas'
                        ),

Those commented functions (trim, required, valid_email) work. But when I want to use my function, it doesn't.

Don't understand why. I tried logging message in that function, to now that it is called, but there is no message in database, so this function was not even called. Have you an idea why?


BTW this project is using HMVC, but I saw there is extended form_validation library, and so on, and all validation is working, except my callback Sad
#2

[eluser]InsiteFX[/eluser]
Read the CodeIgniter User Guide, you cannot add error to the array for one and all rules have to be on one line in the array. Plus you closed the array with a comma it should have been a semicolon. ?It's a comma if you add another array after it.
Code:
array(
   'field' => 'elpastas',
   'label' => 'lang:elpastas',
   'rules' => 'trim|required|valid_email'|'callback_emailcheck',
);

InsiteFX
#3

[eluser]SPeed_FANat1c[/eluser]
Quote:Plus you closed the array with a comma it should have been a semicolon

This was just a piece of code, this array was in array, and there are more arrays, so thats why its was comma.

I did all rules in one line, but after that did not work, I just commented out other rules and added this one in another line.

And for the error message - its interesting then why someone who done this, put all errors this way, which as you say is not valid :/ At least when we don't use my callback function, then email field validation works.

the whole code:
http://pastebin.com/xZUy5dvS

I tried your code, but no luck.


Also tried commenting out all $config array and then make only for email field:
Code:
$config = array(
   'field' => 'elpastas',
   'label' => 'lang:elpastas',
   'rules' => 'trim|required|valid_email|callback_emailcheck',
);


And it had to fail validation with empty field, but, it passed.

Edit:

just tried this way:
Code:
$config = array(
                'register' =>
                    array(
                        
                        array('field' => 'elpastas',
                            'label' => 'lang:elpastas',
                            'rules' => 'trim|required|valid_email|callback_emailcheck',
                            //'rules' => 'callback_emailcheck',
                            //'rules' => 'trim|required|valid_email'|'callback_emailcheck'
                            //'error' => 'elpastasblogas'
                        ),
                      
                    ),
                 );

And with [email protected] it passed the validation (just remind - callback function returns false no matter what).
#4

[eluser]InsiteFX[/eluser]
HMVC you just do this:
Code:
$this->load->library('form_validation');
$this->form_validation->CI =& $this;

InsiteFX
#5

[eluser]danmontgomery[/eluser]
[quote author="InsiteFX" date="1308015057"]HMVC you just do this:
Code:
$this->load->library('form_validation');
$this->form_validation->CI =& $this;

InsiteFX[/quote]

Also,

Code:
if(!$this->form_validation->run($this))

works.
#6

[eluser]SPeed_FANat1c[/eluser]
[quote author="InsiteFX" date="1308015057"]HMVC you just do this:
Code:
$this->load->library('form_validation');
$this->form_validation->CI =& $this;

InsiteFX[/quote]

Awesome Smile this worked Smile

I just don't get how those who coded this project did not use that
Code:
$this->form_validation->CI =& $this;

line.

I did not use this
Code:
if(!$this->form_validation->run($this))

but in the project is used this:
Code:
if ($this->form_validation->run('register') == FALSE ||
                (isset($_FILES['cmr_file']) && $_FILES['cmr_file']['name'] == '') ||
                (isset($_FILES['lic_file']) && $_FILES['lic_file']['name'] == '') ||
                (isset($_FILES['mini_file']) && $_FILES['mini_file']['name'] == ''))

'register' is the current function name, probably it means the same as $this, thats why it works.

Thank you very much.




Theme © iAndrew 2016 - Forum software by © MyBB