Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3396266
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:23:13+00:00 2026-05-18T04:23:13+00:00

I have this form that validates the fields on submit through ajax (using Codeigniter’s

  • 0

I have this form that validates the fields on submit through ajax (using Codeigniter’s Form_Validation Class).

<input type="text" name="field1" id="field1"> />
<span id="field1_error"></span> 
....
<input type="text" name="field2" id="field2"> />
<span id="field2_error"></span> 
...
<input type="text" name="field3" id="field3"> />
<span id="field3_error"></span> 
<input type="submit" name="submit" id="btnPublish" /> 

On submit, jQuery calls CI’s validation method. Which would be the best way to output those validation errors with a single Ajax Call?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:23:14+00:00Added an answer on May 18, 2026 at 4:23 am

    Maybe this approach can help you.. its more like a hint than complete solution…

    On server side you will do validation and return JSON (for example)
    – $progress is true/false – depending on validation result and $errors is array(name,translated_error/ or “”)

    partial php:

    $res = array(
        'progress' => $progress,
        'errors' => $errors
    );
    $jsonReturn = json_encode($res);
    
    //output result
    header('Content-Type: text/html; charset=utf-8');       
    echo $jsonReturn;
    

    partial jQuery:

    var errorFields = $([]).add(field1_error).add(field2_error).add(field3_error),
        mainFields = $([]).add(field1).add(field2).add(field3);
    
    $('#btnPublish').button().click(function(event){
    
        mainFields.removeClass('ui-state-error');
        errorFields.val();                                                  
    
        $.ajax({
        type: 'POST',
        url: your_url,
        data: $('#your_form_id').serialize(),
            async: false,
            success: function (returned_value){
                var obj = $.parseJSON(returned_value);
    
                if (obj.progress==true){
                    alert('Validation successfull');
    
                }else{
                    $.each(obj.errors, function(index, value) { 
                        if (value!=""){ //it will skip those fields with no errors
                            $('#'+index).addClass(('ui-state-error'));
                            $('#'+index+'_error').val(value);
                        }
                    });
    
                }//end return ajax
    
            }//end ajax
        });         
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have asp.net form that contains fields. When I access this window, my javascript
I hope I can explain this right I have two input fields that require
I have a view user control that can post form. This control can be
Say I have this simple form: class ContactForm(forms.Form): first_name = forms.CharField(required=True) last_name = forms.CharField(required=True)
I have this input in a form: <input type=text value=<script src='/js/script.js' type='text/javascript'></script> name=embed/> The
In Kohana/CodeIgniter, I can have a URL in this form: http://www.name.tld/controller_name/method_name/parameter_1/parameter_2/parameter_3 ... And then
I have a form with multiple fields that I'm validating (some with methods added
I have code that opens a dialog, validates, and posts a form when the
I have created a contact form that has a disabled submit button until all
I have this form in my view: <!-- Bug (extra 'i') right here-----------v -->

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.