CodeIgniter Forums
validation error messages and Ajax - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: validation error messages and Ajax (/showthread.php?tid=32895)



validation error messages and Ajax - El Forum - 08-09-2010

[eluser]Ajaxian64[/eluser]
Hi all,

I submit a form via Ajax to a controller
On this controller I do this...
Code:
$this->form_validation->set_rules('description', 'Description', 'required');
$this->form_validation->set_rules('date', 'Date', 'callback_date_check');
$data['event_id'] = $event_id;
if ($this->form_validation->run() == FALSE)
  {        
     if (IS_AJAX) {
    $data['message'] ['message_label'] = form_error('description');
    $data['message'] ['message_date'] = form_error('date');
    echo json_encode($data);
     }
....
And in the function check :
Code:
function date_check($date) {
   // Just this try
   $this->form_validation->set_message('date_check', 'date should be xxx');
   return false;  
}
In my json message I'm unable to have the message from date_check...
I've only the message concerning required
-- My Json Object
{"event_id":"26","message":{"message_label":"<p>required<\/p>","message_date":null}}
--
Do you know why ?
Thanks


validation error messages and Ajax - El Forum - 08-09-2010

[eluser]Ajaxian64[/eluser]
I tried also with validation_errors(); but it gives me "null"


validation error messages and Ajax - El Forum - 08-09-2010

[eluser]Ajaxian64[/eluser]
To sump up the question would be:
Do the validation process with our own check function work with ajax call ?

I mean It seems that
Code:
$this->form_validation->set_rules('dateEvent', 'Date', 'required|callback_dateEvent_check');

function dateEvent_check() {
$this->form_validation->set_message('dateEvent', 'Date bla bla bla');
return false;
}
This mechanism doesn't work...
My Json return <p>Unable to access an error message corresponding to your field name.<\/p>


validation error messages and Ajax - El Forum - 08-09-2010

[eluser]Ajaxian64[/eluser]
Hii Haaaann, Hiiiii Haann saids the donkey.

Seems to be a problem in json_encode

My page was not save in UTF-8 and then when I give a message like

Code:
$this->form_validation->set_message('dateEvent_check', 'bbbbb aaa dd à dddsd ');
then it leads to a problem when I encode it