Welcome Guest, Not a member yet? Register   Sign In
Can't read form values
#25

(This post was last modified: 07-18-2017, 07:43 PM by Junie.)

(07-18-2017, 12:43 PM)Martin7483 Wrote: I give up.

You are doing something which is causing strange behaviour.

Maybe you could attach the files to this post so we could see what you are doing

Sir,

This is my currently code:

Form:
Code:
<div class="col-md-4 col-sm-6 col-xs-12">
 <div class="activity-item">
   <form id="agencyForm" enctype="multipart/form-data" method="POST" class="form-horizontal">
     <div class="form-body">
       <input type="hidden" value="" name="agency_id" />
       <div class="form-group">
         <div class="col-md-12">
           <input name="agency_name" id="agency_name" placeholder="Agency Name" class="form-control" type="text">
           <?php echo form_error('agency_name','<span class="help-block">','</span>'); ?>
         </div>
       </div>
       <div class="form-group">
         <div class="col-md-12">
           <input name="category" id="category" placeholder="Category" class="form-control" type="text">
           <?php echo form_error('category','<span class="help-block">','</span>'); ?>
         </div>
       </div>
       <div class="form-group">
         <div class="col-md-12">
           <input name="address" id="address" placeholder="Address" class="form-control" type="text">
           <?php echo form_error('address','<span class="help-block">','</span>'); ?>
         </div>
       </div>
       <div class="form-group">
         <div class="col-md-12">
           <input name="acronym" id="acronym" placeholder="Acronym" class="form-control" type="text">
           <?php echo form_error('acronym','<span class="help-block">','</span>'); ?>
         </div>
       </div>
     </div>
     <button type="submit" value="submit " id="btnSave" onclick="save(this.agencyForm); return false" class="btn btn-effect">Save</button>
   </form>

 </div>
 <div class="clear"> </div>
</div>
Partially script:
Code:
function save() {
 $('#btnSave').text('saving...');
 $('#btnSave').attr('disabled', true);
 var url;
 // var form = new FormData($("#agencyForm")[0]);        

 if (save_method == 'add') {
   url = "<?php echo site_url('agency/save_c')?>";
 } else {
   // url = "<?php echo site_url('agency/update')?>";
 }

 console.log($('#agencyForm').serialize());
 // alert($(agencyForm).serialize());
 $.ajax({
   url: url,
   type: "POST",
   data: $('#agencyForm').serialize(),
   dataType: "JSON",
   success: function(data) {

     if (data.status) {
       alert('Successfully added the officer');
       reload_table();

     } else {

     }
     $('#btnSave').text('save'); //change button text
     $('#btnSave').attr('disabled', false); //set button enable


   },
   error: function(jqXHR, textStatus, errorThrown) {
     alert('Error adding / update data');
     $('#btnSave').text('save'); //change button text
     $('#btnSave').attr('disabled', false); //set button enable

   }
 });
}

Controller:
Code:
public function save_c()
    {
        
        var_dump($this->input->post(NULL, TRUE));
        // $this->_validate();
        $data = array(
            'agency_name' => $this->input->post('agency_name'),
            'category' => $this->input->post('category'),
            'address' => $this->input->post('address'),
            'acronym' => $this->input->post('acronym'),
        );
        $insert = $this->agency->save_now($data);
        echo json_encode(array("status" => TRUE));
    }
Model:
Code:
public function save_now($data)
   {
       $this->db->insert($this->table, $data);
       return $this->db->insert_id();
   }

NOTE: It insert data into the database when I change the URL like this:
Code:
$.ajax({
           // url: url,
           url: "<?php echo site_url('agency/save_c')?>",
           type: "POST",
           data: $('#agencyForm').serialize(),            
           dataType: "JSON",
           success: function(data) {

               if (data.status)
               {
                alert('Successfully added the officer');
                reload_table();

            } else {

            }
               $('#btnSave').text('save'); //change button text
               $('#btnSave').attr('disabled', false); //set button enable


           },
           error: function(jqXHR, textStatus, errorThrown) {
               alert('Error adding / update data');
               $('#btnSave').text('save'); //change button text
               $('#btnSave').attr('disabled', false); //set button enable

           }
       });

Thanks for the TimeSmile
Reply


Messages In This Thread
Can't read form values - by Junie - 07-13-2017, 10:44 PM
RE: Can't read form values - by Martin7483 - 07-14-2017, 12:29 AM
RE: Can't read form values - by Junie - 07-14-2017, 12:59 AM
RE: Can't read form values - by salain - 07-14-2017, 03:23 AM
RE: Can't read form values - by Joel Catantan - 07-14-2017, 02:50 PM
RE: Can't read form values - by Paradinight - 07-14-2017, 11:14 PM
RE: Can't read form values - by Junie - 07-16-2017, 08:39 PM
RE: Can't read form values - by Martin7483 - 07-16-2017, 11:51 PM
RE: Can't read form values - by Junie - 07-17-2017, 12:12 AM
RE: Can't read form values - by Paradinight - 07-17-2017, 08:26 PM
RE: Can't read form values - by Junie - 07-18-2017, 06:27 AM
RE: Can't read form values - by Martin7483 - 07-18-2017, 02:01 AM
RE: Can't read form values - by Junie - 07-18-2017, 06:32 AM
RE: Can't read form values - by Junie - 07-18-2017, 06:39 AM
RE: Can't read form values - by Junie - 07-18-2017, 06:43 AM
RE: Can't read form values - by Martin7483 - 07-18-2017, 06:50 AM
RE: Can't read form values - by Junie - 07-18-2017, 07:09 AM
RE: Can't read form values - by Martin7483 - 07-18-2017, 07:14 AM
RE: Can't read form values - by Junie - 07-18-2017, 07:26 AM
RE: Can't read form values - by Martin7483 - 07-18-2017, 07:27 AM
RE: Can't read form values - by Junie - 07-18-2017, 07:32 AM
RE: Can't read form values - by Martin7483 - 07-18-2017, 07:45 AM
RE: Can't read form values - by Junie - 07-18-2017, 07:49 AM
RE: Can't read form values - by Martin7483 - 07-18-2017, 12:43 PM
RE: Can't read form values - by Junie - 07-18-2017, 06:55 PM
RE: Can't read form values - by salain - 07-18-2017, 09:58 PM
RE: Can't read form values - by Junie - 07-18-2017, 10:47 PM
RE: Can't read form values - by Martin7483 - 07-19-2017, 01:49 AM
RE: Can't read form values - by Junie - 07-19-2017, 05:12 AM
RE: Can't read form values - by Paradinight - 07-22-2017, 04:29 AM
RE: Can't read form values - by Junie - 07-22-2017, 07:23 AM
RE: Can't read form values - by Paradinight - 07-22-2017, 07:34 AM
RE: Can't read form values - by Junie - 07-22-2017, 07:39 AM
RE: Can't read form values - by Paradinight - 07-22-2017, 07:44 AM
RE: Can't read form values - by Junie - 07-22-2017, 08:03 AM
RE: Can't read form values - by Paradinight - 07-22-2017, 08:08 AM
RE: Can't read form values - by Junie - 07-22-2017, 08:16 AM
RE: Can't read form values - by Paradinight - 07-22-2017, 08:26 AM
RE: Can't read form values - by Junie - 07-22-2017, 08:31 AM
RE: Can't read form values - by Paradinight - 07-22-2017, 08:37 AM
RE: Can't read form values - by Junie - 07-22-2017, 08:39 AM
RE: Can't read form values - by Junie - 07-22-2017, 08:37 AM
RE: Can't read form values - by Paradinight - 07-22-2017, 08:42 AM
RE: Can't read form values - by Junie - 07-22-2017, 08:55 AM
RE: Can't read form values - by Paradinight - 07-22-2017, 09:06 AM
RE: Can't read form values - by Junie - 07-22-2017, 09:16 AM
RE: Can't read form values - by Paradinight - 07-22-2017, 09:26 AM
RE: Can't read form values - by Junie - 07-22-2017, 09:29 AM
RE: Can't read form values - by Paradinight - 07-22-2017, 09:35 AM
RE: Can't read form values - by Junie - 07-22-2017, 09:45 AM
RE: Can't read form values - by Paradinight - 07-22-2017, 09:49 AM
RE: Can't read form values - by Junie - 07-22-2017, 07:38 PM
RE: Can't read form values - by Paradinight - 07-22-2017, 10:29 PM
RE: Can't read form values - by Junie - 07-25-2017, 04:20 AM
RE: Can't read form values - by Paradinight - 07-25-2017, 11:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB