php - Two buttons on one form in CodeIgniter -


my goal have 2 buttons allocated 1 form. 1 of buttons, when clicked, edits ticket, second button deletes ticket. form submitted via ajax controller, directs action appropriately. have tried far send submit value via ajax controller , read there, , call appropriate model update database, not working.

here relevant code:

the form submit buttons (in view):

<div class="form-group">     <div class="col-sm-5 col-sm-offset-7">         <input id="type" style='font-size:18px; margin-left: 35px; margin-top: 10px;' name="submit" type="submit" value="edit ticket" class="btn btn-lg btn-success">     </div>     <div class="col-sm-3 col-sm-offset-9">         <input id="type" style='font-size:18px; margin-left: 35px; margin-top: -65px;' name="submit" type="submit" value="delete ticket" class="btn btn-lg btn-danger">         </div> </div> 

the receiving controller:

public function editexistingticket(){     $this->load->model('tickets');     $ticketid = $this->input->post('ticketid');      if ($this->input->post('submit') == 'edit ticket') {         $ticket = array(                   'ticketid'    => $ticketid,                   'category'    => $this->input->post('category'),                   'headline'    => $this->input->post('headline'),                   'description' => $this->input->post('description'),                   'assigned'    => $this->input->post('assigned'),                   'open'        => $this->input->post('status'),                   'priority'    => $this->input->post('priority')                 );         $edited = $this->tickets->editticket($ticket);     }      if($this->input->post('submit') == 'delete ticket') {         $this->tickets->deleteticketbyid($ticketid);     } } 

the model:

public function editticket($ticket) {     $q = $this->db->where('ticketid', $ticket['ticketid']);     $q = $this->db->update('tickets', $ticket);     $results = $this->db->affected_rows();     return $results; } 

am missing easy? or strategy doing incorrect?

thanks help!!

ids of both submit button should different like

$("#type1").click(function(){    // code    return false;  });    $("#type2").click(function(){    // code    return false;  });
<div class="form-group">      <div class="col-sm-5 col-sm-offset-7">          <input id="type1" style='font-size:18px; margin-left: 35px; margin-top: 10px;' name="submit" type="submit" value="edit ticket" class="btn btn-lg btn-success">      </div>      <div class="col-sm-3 col-sm-offset-9">          <input id="type2" style='font-size:18px; margin-left: 35px; margin-top: -65px;' name="submit" type="submit" value="delete ticket" class="btn btn-lg btn-danger">          </div>  </div>


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -