2016-11-20 3 views
0

У меня есть представление в моем проекте (PHP codeigniter), где пользователь может подтвердить или удалить определенную запись из отображаемой таблицы данных. Когда пользователь выбирает подтверждение записи, появляется модальное всплывающее окно, подтверждающее подтверждение. Нажатие на кнопку Подтверждение в этом модальном вызове вызовет метод контроллера для надлежащего обновления таблицы БД посредством последующего вызова метода модели. То же самое относится к функции удаления в представлении. Я применил и назвал все соответствующие методы, но это никак не влияет.Модальное подтверждение в Codeigniter PHP

код в контексте

1.View

<body> 
    <div class="content" style="background-color: white"> 
     <div class="container-fluid" style="overflow-y: auto"> 

      <legend>Vacancies Applied</legend> 
      <div> 
       <form class="form-horizontal" id="viewVacancy"> 
        <?php echo $this->session->flashdata('msgconfirmed'); 
        echo $this->session->flashdata('msgremoved');?> 

        <table class="table" id="vacancyApplicationTable" > 
         <thead class="active"> 
         <tr style="background-color: lightblue;color: white" > 
          <th class="hidden-lg hidden-lg">ID</th> 
          <th>Company</th> 
          <th>Job Title</th> 
          <th>Applied Date</th> 
          <th>Closing Date</th> 
          <th>Status</th> 
          <th></th> 
          <th></th> 
         </tr> 
         </thead> 
         <tbody > 
         <?php 
         if(count($vacanciesApplied)>0) { 
          foreach ($vacanciesApplied as $row) { ?> 
           <tr> 
            <td class="hidden-lg hidden-lg"><a><?php echo $row->vid; ?></a></td> 
            <td><?php echo $row->onBehalfOf; ?></td> 
            <td><?php echo $row->jobTitle; ?></td> 
            <td><?php echo $row->appliedDate; ?></td> 
            <td><?php echo $row->closingDate; ?></td> 
            <?php 
            if ($row->status == "pending") 
            { 
             $status = "Pending"; 
             ?> 
             <td><?php echo $status ?></td> 
             <td></td> 
             <td><a data-toggle="modal" data-name="<?php echo $row->vid; ?>" data-id="<?php echo $row->studentId; ?>" title="Add this item" class="open-AddBookDialog btn btn-danger" href="#deleteVacancyApplication">Remove</a></td> 
             <?php 
            } 
            else 
            { 
             $status = "Accepted"; ?> 
             <td class="blink_text"><?php echo $status ?></td> 
             <td><a data-toggle="modal" data-name="<?php echo $row->vid; ?>" data-id="<?php echo $row->studentId; ?>" title="Add this item" class="open-AddBookDialog btn btn-info" href="#confirmVacancyStatus">Confirm</a></td> 
             <td><a data-toggle="modal" data-name="<?php echo $row->vid; ?>" data-id="<?php echo $row->studentId; ?>" title="Add this item" class="open-AddBookDialog btn btn-danger" href="#deleteVacancyApplication">Remove</a></td> 
             <?php 
            } 
            ?> 
           </tr> 
          <?php } 
         } 
         ?> 
         </tbody> 
        </table> 
       </form> 
      </div> 
     </div> 
    </div> 
</body> 

<script> 
    $(function() { 
     $('#vacancyApplicationTable').DataTable({ 
      "paging": true, 
      "lengthChange": true, 
      "searching": true, 
      "ordering": true, 
      "info": true, 
      "autoWidth":true 
     }); 
    }); 
</script> 

<script> 
    $(document).on("click", ".open-AddBookDialog", function() { 
     var studentId = $(this).data('id'); 
     var vid = $(this).data('name'); 
     $(".modal-body #uid").val(studentId); 
     $(".modal-body #vid").val(vid); 
    }); 
</script> 

<!-- Modal for confirmVacancyStatus --> 
<div class="modal fade" id="confirmVacancyStatus" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-keyboard="false" data-backdrop="false"> 
    <div class="modal-dialog"> 
     <div class="modal-content"> 
      <div class="modal-header" style="background-color:lawngreen"> 
       <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 
       <h4 id="uid"><i class="glyphicon glyphicon-check"></i>&nbsp;Confirm</h4> 
      </div> 
      <div class="modal-body"> 
       <form method="post" id="formConfirm" action="<?php echo base_url() . 'index.php/studentDashboardController/confirmVacancy'?>"> 
        <input type="text" name="vid" id="vid" value="" hidden/> 
        <div class="form-group"> 
         <p>You got Accepted to follow this vacancy</p> 
         <p>Do you confirm this?</p> 
        </div> 
       </form> 
      </div> 
      <div class="modal-footer"> 
       <button type="submit" class="btn btn-success pull-right">Confirm</button> 
      </div> 
     </div> 
    </div> 
</div> 

<!-- Modal for deleteVacancyApplication --> 
<div class="modal fade" id="deleteVacancyApplication" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-keyboard="false" data-backdrop="false"> 
    <div class="modal-dialog"> 
     <div class="modal-content"> 
      <div class="modal-header" style="background-color:red"> 
       <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 
       <h4 id="uid"><i class="glyphicon glyphicon-remove"></i>&nbsp;Cancel</h4> 
      </div> 
      <div class="modal-body"> 

       <form method="post" id="form" action="<?php echo base_url() . "index.php/studentDashboardController/deleteVacancyRequest"?>"> 
        <input type="text" name="vid" id="vid" value="" hidden/> 
        <div class="form-group"> 
         <p>Are you sure you want to cancel your application for this vacancy</p> 
        </div> 
       </form> 
      </div> 
      <div class="modal-footer"> 
       <button type="submit" class="btn btn-danger pull-right">Cancel Application</button> 
      </div> 
     </div> 
    </div> 
</div> 

2.Controller- studentDashboardController/confirmVacancy

public function confirmVacancy() 
{ 
    if (isset($this->session->userdata['logged_in'])) 
    { 
     $uid = ($this->session->userdata['logged_in']['userId']); 

     $data['notifyCount']= $this->notifications->getUnreadNotification($uid); 
     $data['title']= $this->notifications->getUnreadNotificationTitle($uid); 
     $data['notifyCount']= $this->notifications->getUnreadNotification($uid); 
     $data['users'] = $this->user->getUserNames(); 

     $msg = $this->vacancyModel->confirmVacancyApplication($uid,$this->input->post()); 
     $msgText = $msg['msg']; 
     $msgType = $msg['type']; 
     //Loading View 
     if($msgType == "danger") 
     { 
      $this->session->set_flashdata('msgconfirmed', '<div class="alert alert-danger text-center">'.$msgText.'</div>'); 
     } 
     else 
     { 
      $this->session->set_flashdata('msgconfirmed', '<div class="alert alert-success text-center">'.$msgText.'</div>'); 
     } 

     redirect(base_url('index.php/studentDashboardController/displayVacanciesApplied')); 
    } 
    else 
    { 
     $this->load->view('login/loginView'); 
    } 
} 

3.Model- vacancyModel-> со nfirmVacancyApplication

public function confirmVacancyApplication($uid, $post) 
{ 
    $vid = $post['vid']; 
    $data = array(
     'availability' => $vid+"" 
    ); 
    $this->db->where("uid", $uid); 
    $status = $this->db->update("studentprofile", $data); 
    if($status) 
    { 
     $msg = "You have successfully confirmed"; 
     $type = "success"; 
     $msgData = array(
      'msg' => $msg, 
      'type' => $type 
     ); 
     return $msgData; 
    } 
    else 
    { 
     $msg = "Sorry. This vacancy could not be confirmed"; 
     $type = "danger"; 
     $msgData = array(
      'msg' => $msg, 
      'type' => $type 
     ); 
     return $msgData; 
    } 
} 

Интерфейсы

Confirm

Любые предложения в этой связи будут высоко оценены.

ответ

1

Вы закрываете перед отправкой кнопку. Положить форму после ввода типа = "отправить" тег. Он будет работать

+0

Спасибо миллион. Такая тривиальная ошибка. –

+0

Прошу проголосовать за мой ответ. благодаря – 438sunil

Смежные вопросы