Codeigniter form validation not working while using Ajax form submission ... |
[eluser]Kiran cet[/eluser]
This is my Ajax form submission code. Code: [removed] But while submission the codeigniter form validation not working ?? Please help me. How can i fix it ?
[eluser]rwestergren[/eluser]
The form validation code is server-side, so we'd need to see your "registration" function. You may also want to look into the jQuery Form Plugin rather than manually getting the values of your form.
[eluser]Kiran cet[/eluser]
This is my Controller Code: class College_registration extends CI_Controller how can i use is_ajax_request() in my controller ? how to use json_encode() ? i am printing error message using form_error('field name') , is not printing while using ajax submission .
[eluser]CroNiX[/eluser]
[quote author="rwestergren" date="1343234794"] You may also want to look into the jQuery Form Plugin rather than manually getting the values of your form.[/quote] jQuery has a built in function for that. $(form_id).serialize();
[eluser]CroNiX[/eluser]
[quote author="Kiran cet" date="1343235606"] how can i use is_ajax_request() in my controller ? how to use json_encode() ? i am printing error message using form_error('field name') , is not printing while using ajax submission .[/quote] Code: if ($this->input->is_ajax_request()) Code: echo json_encode($array); I'm not sure how you expect to use form_error(), which is PHP/CI, directly with javascript. if there are form errors, use validation_errors() in your controller and send back the resulting HTML and display the errors in a div. I usually do something like: Code: $data['status'] = $this->form_validation->run(); //did we pass validation? Then in the success event of your ajax call...something like: Code: success: function(data) {
[eluser]Kiran cet[/eluser]
Thanks for your support. I have almost done. I have another doubt with how to access the form variable in my controller.. ?? Currently i am accessed it through Code: $this->input->post('college_code') Thanks...
[eluser]kakallatt[/eluser]
[quote author="CroNiX" date="1343243633"][quote author="Kiran cet" date="1343235606"] how can i use is_ajax_request() in my controller ? how to use json_encode() ? i am printing error message using form_error('field name') , is not printing while using ajax submission .[/quote] Code: if ($this->input->is_ajax_request()) Code: echo json_encode($array); I'm not sure how you expect to use form_error(), which is PHP/CI, directly with javascript. if there are form errors, use validation_errors() in your controller and send back the resulting HTML and display the errors in a div. I usually do something like: Code: $data['status'] = $this->form_validation->run(); //did we pass validation? Then in the success event of your ajax call...something like: Code: success: function(data) { Please help me. This is my controller. Code: $this->form_validation->set_rules("title","Title","trim|required|max_length[128]|xss_clean"); Ajax: Code: [removed] Final, in my view has a div to show message. Code: <div id="my-error-display-div"></div> But the form validation not working when I click submit button. Please help me. Thank you so much!!!! |
Welcome Guest, Not a member yet? Register Sign In |