title: Codeigniter form validation not working in modal
body: <p>I have controller and view modal where i'm validating the data in controller on click of button where the errors are supposed to appear in view. The form is getting submitted without validation of the required fields. The code is as follows:</p>
  
  <p>Controller:</p>
  
  <pre><code>class task extends  CI_Controller {
  public function __construct()
      {
          parent::__construct();
          $this-&gt;load-&gt;library('session');$this-&gt;load-&gt;helper(array('form', 'url'));
          $this-&gt;load-&gt;library('form_validation');
          $this-&gt;load-&gt;helper('security');}
      public function task_display()
      {
        if($this-&gt;input-&gt;post('add'))
          {
              $this-&gt;form_validation-&gt;set_rules('code','TaskCode','required | integer');
              if($this-&gt;form_validation-&gt;run() == TRUE) {
                  $tname=$this-&gt;input-&gt;post('name');
                  $tcode=$this-&gt;input-&gt;post('code');
                  $tcategory=$this-&gt;input-&gt;post('category');
                  $this-&gt;task_model-&gt;add_task($tname,$tcode,$tcategory);  
              }
          }
       }
  </code></pre>
  
  <p>View: (modal)</p>
  
  <pre><code>&lt;div id="addmodal" class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true" &gt;
                      &lt;div class="modal-dialog modal-lg"&gt;
                      //content
                      //header
                      //title
                      //body
                      &lt;?php echo validation_errors(); ?&gt;
                      &lt;form class="form-horizontal form-label-left input_mask " method="post" id="addmodalform"&gt;
                       &lt;div class="form-group"&gt;
                          &lt;label class="control-label"&gt;Task Code&lt;span class="required"&gt;*&lt;/span&gt;&lt;/label&gt;
                          &lt;div class="col-md-9 col-sm-9 col-xs-12"&gt;
                            &lt;input  name="task_code" id="task_code" type="text" class="form-control"  placeholder="Task Code" required="required"&gt;
                          &lt;/div&gt;
                        &lt;/div&gt;
                        //closing div
                        &lt;div class="modal-footer"&gt;
                            &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
                            &lt;input type="hidden" name="addtask_hidden" id="addtask_hidden" value=""&gt;
                            &lt;button type = "button" id="addnew" class = "btn btn-primary" &gt;Add&lt;/button&gt;
                          &lt;/div&gt;
  </code></pre>
  
  <p>Here goes ajax code:</p>
  
  <pre><code>$(document).on('click', '#addnew', function(){
  {
             var addtask_hide=document.getElementById('addtask_hidden').value;
             if(addtask_hide==1)
         {
           $('#addmodal').modal('hide');
          $('body').removeClass('modal-open');
        $('.modal-backdrop').remove();
        $.ajax({
            type: "POST",
            url: "&lt;?php echo base_url(); ?&gt;" + "index.php/task/task_display",
            data: {
            add: 1,
            },
             success: function(){
              console.log("success");
            }
             });
          }
          });
  </code></pre>
  
  <p>I have loaded the required libraries and have set the rules accordingly and even then the form is not getting validated on click of button. How will i make it work?</p>