Passing data on a bootstrap model and submitting to db with code igniter
<p>am making an application with twitter bootstrap and code igniter. I have a form that have developed using bootstrap modal and passing the data from the view using ajax to controller. But unfortunately when submit the form it does not store the data in the db.</p>

<p><strong>Model</strong></p>

<pre><code>public function get_primary()
{
  $this-&gt;db-&gt;select('primary_id'); 
  $this-&gt;db-&gt;select('category'); 
  $this-&gt;db-&gt;from('primary_category'); 
  $query = $this-&gt;db-&gt;get();
  $result = $query-&gt;result();

   //array to store primary id &amp; category
   $prim_id = array('Select Primary Category'); 
   $cate = array('Select Primary Category');

     for ($i = 0; $i &lt; count($result); $i++) {
      array_push($prim_id, $result[$i]-&gt;primary_id);
      array_push($cate, $result[$i]-&gt;category); }
      return $primary_result = array_combine($prim_id, $cate);
}
</code></pre>

<p><strong>View</strong></p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;script type="text/javascript"&gt;
      $('#submit').click(function() {
          var form_data = {
              title: $('#title').val(),
              pcategory: $('#pcategory').val(),
              scategory: $('#scategory').val(),
              sdescription: $('#sdescription').val(),
              description: $('#description').val(),
              benefits: $('#benefits').val(),
              hours: $('#hours').val()
              area: $('#area').val()
              location: $('#location').val()
              dateline: $('#dateline').val()
              vacancies: $('#vacancies').val()
          };
          $.ajax({
              url: "&lt;?php echo site_url('Company/profilesearch'); ?&gt;",
              type: 'POST',
              data: form_data,
              success: function(msg) {
                  if (msg == 'YES')
                      $('#alert-msg').html('&lt;div class="alert alert-success text-center"&gt;Posted successfully!&lt;/div&gt;');
                  else if (msg == 'NO')
                      $('#alert-msg').html('&lt;div class="alert alert-danger text-center"&gt;Error while submiting your internship.&lt;/div&gt;');
                  else
                      $('#alert-msg').html('&lt;div class="alert alert-danger"&gt;' + msg + '&lt;/div&gt;');
              }
          });
          return false;
      });
    &lt;/script&gt;</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="modal fade modal-success clearfix" id="postNewInternship" aria-hidden="true" aria-labelledby="postNewInternship" role="dialog" tabindex="-1"&gt;
  &lt;div class="modal-dialog"&gt;
    &lt;div class="modal-content"&gt;
        &lt;div class="modal-header"&gt;
            &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;
              &lt;span aria-hidden="true"&gt;×&lt;/span&gt;
            &lt;/button&gt;
          &lt;h4 class="modal-title"&gt;Post A new internship.&lt;/h4&gt;
        &lt;/div&gt;
        &lt;div class="modal-body"&gt;
         &lt;?php  echo form_open('Company/profilesearch');?&gt;
          &lt;div class="form-group"&gt;
            &lt;input type="text" id="tittle" name="tittle" class="form-control" value="" required="required" pattern="" title="" placeholder="Tittle of the internship"&gt;
              &lt;span class="text-danger small"&gt;&lt;?php echo form_error('tittle'); ?&gt;&lt;/span&gt;
          &lt;/div&gt;
            &lt;div class="form-group"&gt;
              &lt;?php $attributes = 'class = "form-control" id = "pcategory"'; echo form_dropdown('primary',$primary,set_value('primary'),$attributes);?&gt;
              &lt;span class="text-danger small"&gt;&lt;?php echo form_error('pcategory'); ?&gt;&lt;/span&gt;
            &lt;/div&gt;
            &lt;div class="form-group"&gt;
              &lt;?php $attributes = 'class = "form-control" id = "scategory"';
                             echo form_dropdown('secondary',$secondary,set_value('secondary'),
                            $attributes);?&gt;
              &lt;span class="text-danger small"&gt;&lt;?php echo form_error('scategory'); ?&gt;&lt;/span&gt;
            &lt;/div&gt;
            &lt;div class="form-group"&gt;
              &lt;textarea class="form-control"  id="description" name="sdescription" rows="3" placeholder=" Enter short description of your internship for search..must be 140 words."&gt;&lt;/textarea&gt;
              &lt;span class="text-danger small"&gt;&lt;?php echo form_error('scategory'); ?&gt;&lt;/span&gt;
            &lt;/div&gt;
            &lt;div class="form-group"&gt;
              &lt;textarea class="form-control"  id="description" name="description" rows="3" placeholder="Enter your description of your internship..must be 500+ words."&gt;&lt;/textarea&gt;
              &lt;span class="text-danger small"&gt;&lt;?php echo form_error('description'); ?&gt;&lt;/span&gt;
            &lt;/div&gt;
            &lt;div class="form-group"&gt;
              &lt;div class="row"&gt;
                &lt;div class="col-md-6"&gt;
                  &lt;?php $attributes = 'class = "form-control" id = "benefits"';
                    echo form_dropdown('benefits',$benefits,set_value('benefits'),
                  $attributes);?&gt;
                  &lt;span class="text-danger small"&gt;&lt;?php echo form_error('benefits'); ?&gt;&lt;/span&gt;
                &lt;/div&gt;
                &lt;div class="col-md-6"&gt;
                  &lt;?php $attributes = 'class = "form-control" id = "hours"';
                    echo form_dropdown('hours',$hours,set_value('hours'),
                  $attributes);?&gt;
                  &lt;span class="text-danger small"&gt;&lt;?php echo form_error('hours'); ?&gt;&lt;/span&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="form-group"&gt;
              &lt;div class="row"&gt;
                &lt;div class="col-md-6"&gt;
                  &lt;input type="text" id="area" name="area" class="form-control" value="" required="required" pattern="" title="" placeholder="Physical area"&gt;
                &lt;/div&gt;
                &lt;div class="col-md-6"&gt;
                  &lt;?php $attributes = 'class = "form-control" id = "location"';
                    echo form_dropdown('location',$location,set_value('location'),
                  $attributes);?&gt;
                  &lt;span class="text-danger small"&gt;&lt;?php echo form_error('location'); ?&gt;&lt;/span&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

            &lt;div class="form-group"&gt;
              &lt;div class="row"&gt;
                &lt;div class="col-md-7"&gt;
                  &lt;div class="input-group"&gt;
                      &lt;span class="input-group-addon"&gt;
                        &lt;i class="icon md-calendar" aria-hidden="true"&gt;&lt;/i&gt;
                      &lt;/span&gt;
                      &lt;input type="text" id="dateline" name="dateline" class="form-control" data-plugin="datepicker" data-multidate="true"&gt;
                      &lt;span class="text-danger small"&gt;&lt;?php echo form_error('dateline'); ?&gt;&lt;/span&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
                &lt;div class="col-md-5 pull-right"&gt;
                    &lt;div class="input-group"&gt;
                    &lt;input type="text" id="vacancies" name="vacancies" class="form-control" data-plugin="asSpinner" value="0" /&gt;
                    &lt;span class="text-danger small"&gt;&lt;?php echo form_error('vacancies'); ?&gt;&lt;/span&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="form-group"&gt;
          &lt;/div&gt;
            &lt;div id="alert-msg"&gt;&lt;/div&gt;
            &lt;!-- &lt;/form&gt; --&gt;
          &lt;/div&gt;
          &lt;div class="modal-footer"&gt;
             &lt;input  type="reset"  class="btn btn-danger" data-dismiss="modal" value="Cancel" /&gt;
             &lt;input  type="submit" name="submit" id="submit" class="btn btn-primary" value="Publish" /&gt;
          &lt;/div&gt;
           &lt;?php echo form_close(); ?&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;</code></pre>
</div>
</div>
</p>

<p><strong>Controller</strong></p>

<pre><code>public function profilesearch(){
        $title['title'] = 'Profile Search | InternCube';

        // $this-&gt;load-&gt;library('pagination');
        $this-&gt;load-&gt;model('Company_model');
        $this-&gt;load-&gt;library('form_validation');
        $data['primary'] = $this-&gt;Company_model-&gt;get_primary(); 
        $data['secondary'] = $this-&gt;Company_model-&gt;get_secondary();
        $data['benefits'] = $this-&gt;Company_model-&gt;get_benefit(); 
        $data['hours'] = $this-&gt;Company_model-&gt;get_hours();
        $data['location'] = $this-&gt;Company_model-&gt;get_location();
        $data['myprofilesearch'] = $this-&gt;Company_model-&gt;get_profilesearch();

        $this-&gt;form_validation-&gt;set_rules('tittle', 'Title of the internship', 'trim|required');
        $this-&gt;form_validation-&gt;set_rules('pcategory', 'Primary Category', 'callback_combo_check'); 
        $this-&gt;form_validation-&gt;set_rules('scategory', 'Secondary Category', 'callback_combo_check'); 
        $this-&gt;form_validation-&gt;set_rules('sdescription', 'Shot Description of the position', 'trim|required|xss_clean');
        $this-&gt;form_validation-&gt;set_rules('description', 'Description of the position', 'trim|required');
        $this-&gt;form_validation-&gt;set_rules('benefits', 'Benefits', 'callback_combo_check'); 
        $this-&gt;form_validation-&gt;set_rules('hours', 'Hours', 'callback_combo_check');
        $this-&gt;form_validation-&gt;set_rules('area', 'Physical location', 'trim|required|callback _alpha_only_space');
        $this-&gt;form_validation-&gt;set_rules('location', 'Location', 'callback_combo_check');
        $this-&gt;form_validation-&gt;set_rules('vacancies', 'No of Vacancies', 'trim|required|numeric');
        $this-&gt;form_validation-&gt;set_rules('dateline', 'Deadline', 'required');

        if ($this-&gt;form_validation-&gt;run() == FALSE) {
        //fail validation
        $this-&gt;load-&gt;view('template/header', $title);
        $this-&gt;load-&gt;view('company/profilesearch',$data);
        $this-&gt;load-&gt;view('template/footer');
       }
         else
        {
          // pass validation
         $data = array(
                    'tittle' =&gt; $this-&gt;input-&gt;post('tittle'),
                    'short_description' =&gt; $this-&gt;input &gt;post('sdescription'),
                    'description' =&gt; $this-&gt;input-&gt;post('description'),
                    'primary_id' =&gt; $this-&gt;input-&gt;post('pcategory'),
                    'secondary_id' =&gt; $this-&gt;input-&gt;post('scategory'),
                    'benefit_id' =&gt; $this-&gt;input-&gt;post('benefits'),
                    'hours_id' =&gt; $this-&gt;input-&gt;post('hours'),
                    'location_id' =&gt; $this-&gt;input-&gt;post('location'),
                    'deadline' =&gt; @date('Y-m-d', @strtotime($this-&gt;input-&gt;post('dateline'))), 
                    'vacancies' =&gt; $this-&gt;input-&gt;post('vacancies'),
              );

        // insert the form data into database
        $this-&gt;db-&gt;insert('internship_oppotunity', $data);

        // display success message
        $this-&gt;session-&gt;set_flashdata('msg', '&lt;div class="alert alert-success text-center"&gt;Employee deta ils added to Database!!!&lt;/div&gt;');
         redirect('Company/profilesearch'); 
    } 
}
</code></pre>