title: form validation with ajax and codeigniter
body: <p>i want to use form validation library in ci on html popup and show errors to client when client request if validation error == True update row in database and if validation error = False show field error to client</p>
  
  <p>my html popup code : </p>
  
  <pre><code>&lt;div class="row"&gt;
      &lt;div class="form-group col-lg-6"&gt;
          &lt;label class="col-sm-4 control-label"&gt;tarh&lt;/label&gt;
          &lt;div class="col-sm-8 control-label"&gt;
              &lt;input type="text" name="modal_tarh" id="modal_tarh" class="form-control"&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group col-lg-6"&gt;
          &lt;label class="col-sm-3 control-label"&gt;agreement number&lt;/label&gt;
          &lt;div class="col-sm-6 control-label"&gt;
              &lt;input type="text" name="modal_agreement_number" id="modal_agreement_number" class="form-control"&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;button type="button" class="btn btn-info" id="edit_agreement"&gt;edit&lt;/button&gt;
  </code></pre>
  
  <p>ajax code :</p>
  
  <pre><code>$(document).ready(function() {
  
      $("#edit_agreement").click(function () {
          var String_Url = "address";
          var String_Method = "POST";
          data_send = {
  
              'f1':$("#modal_tarh").val(),
              'f2':$("#modal_agreement_number").val()
          };
          $.ajax({
              url:String_Url,
              type:String_Method,
              data:data_send,
              contentType: 'application/json',
              success:function(callbackData, status, xhr){
                  alert(callbackData)
                  console.log(callbackData)
  
              },
              error:function(xhr, status, err){
  
                  alert(xhr.status);
              }
          });
      });
  
  });
  </code></pre>
  
  <p>codeigniter controller</p>
  
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
  class Portal extends My_controller
  {
  
  public function editAgreement()
      {
          $this-&gt;load-&gt;library('form_validation');
  
          $config = array(
              array(
                  'field'   =&gt; 'modal_tarh',
                  'label'   =&gt; 'tarh',
                  'rules'   =&gt; 'required',
                  'errors' =&gt; array
                  (
                      'required' =&gt; 'pls fill %s  .',
                  )
              ),
              array(
                  'field'   =&gt; 'modal_agreement_number',
                  'label'   =&gt; 'agreement number',
                  'rules'   =&gt; 'required',
                  'errors' =&gt; array
                  (
                      'required' =&gt; 'pls fill %s  .',
                  )
              )
          );
  
          $this-&gt;form_validation-&gt;set_rules($config);
  
          if ($this-&gt;form_validation-&gt;run() == FALSE)
          {
              echo validation_errors();
          }
          else
          {
              redirect('admin/portal/');
          }
      }
  }
  </code></pre>
  
  <p>callbackData in ajax Contains http status code 200 and No data</p>