dongsuishou8039 2017-04-05 15:31
浏览 41

select选项没有将值传递给codeigniter中的控制器函数

I am trying to save all the values as an array using select2 ajax selectbox (selectbox2.github.io) but my controller class is not getting any value from the view class in the codeigniter, I replaced the select2 box with normal textbox, then it works correctly.

Questions:
1. why select2 is not passing values to my controller class or my controller class is not picking up the values from the view class.

2. I have created append class function to add new blank row of select2 elements, when my page load the append functions works correctly but when I am trying to call the same function on click event nothing appears on screen.

code of view class

<hr />
<?php
echo form_open(base_url().'index.php?admin/classroutine_bulk_add/create',
  array('class' => 'form-inline validate', 'style' => 'text-align:center'));
?>
<div class="row">
  <div class="col-md-1"></div>
  <div class="col-md-3">
    <div class="form_group">
      <label class="control-label" style="margin-bottom: 5px;">
        <?php echo get_phrase('class'); ?>
      </label>
      <select name="class_id" id="class_id" class="form-control selectboxit" required="required"
              onchange="get_sections(this.value)"  data-validate="required"  data-message-required="
              <?php echo get_phrase('value_required'); ?>">
        <option value="">
          <?php echo get_phrase('select_branch'); ?>
        </option>
        <?php
        $classes = $this->db->get('class')->result_array();
        foreach($classes as $row):
          ?>
          <option value="
                  <?php echo $row['class_id']; ?>">
                    <?php echo $row['name']; ?>
          </option>
        <?php endforeach; ?>
      </select>
    </div>
  </div>
  <div id="section_holder"></div>
  <div class="col-md-3"></div>
</div>
<br>
<br>
<div id="bulk_add_form">
  <div id="classroutine_entry">
    <div class="row" style="margin-bottom:10px;">
      <div class="form-group">
        <select name="day[]" id="day" class="form-control select2" style="width: 130px; margin-left: 5px;">
          <option value="">
            <?php echo get_phrase('day'); ?>
          </option>
          <option value="mon">
            <?php echo get_phrase('monday'); ?>
          </option>
          <option value="tue">
            <?php echo get_phrase('tuesday'); ?>
          </option>
          <option value="wed">
            <?php echo get_phrase('wednesday'); ?>
          </option>
          <option value="thurs">
            <?php echo get_phrase('thursday'); ?>
          </option>
          <option value="fri">
            <?php echo get_phrase('friday'); ?>
          </option>
        </select>
      </div>
      <div class="form-group">
        <select name="period_id[]" id="period_id" class="form-control select2" data-validate="required"
                data-message-required="
                <?php echo get_phrase('value_required'); ?>" style="width: 130px; margin-left: 15px;">
          <option value="">
            <?php echo get_phrase('period'); ?>
          </option>
          <?php
          $periods = $this->db->get('period')->result_array();
          foreach($periods as $row):
            ?>
            <option value="
                    <?php echo $row['period_id']; ?>">
                      <?php echo $row['name']; ?>
                      <?php echo $row['time']; ?>
            </option>
            <?php
          endforeach;
          ?>
        </select>
      </div>
      <div class="form-group">
        <select name="subject_id[]" id="subject_id" class="form-control select2" style="width: 140px; margin-left: 5px;">
          <option value="">
            <?php echo get_phrase('subject'); ?>
          </option>
          <?php
          $subjects = $this->db->get('subject')->result_array();
          foreach($subjects as $row):
            ?>
            <option value="
                    <?php echo $row['subject_id']; ?>">
                      <?php echo $row['name']; ?>
            </option>
          <?php endforeach; ?>
        </select>
      </div>
      <div class="form-group">
        <select name="room_id[]" id="room_id"  class="form-control select2" style="width: 150px; margin-left: 5px;">
          <option value="">
            <?php echo get_phrase('room'); ?>
          </option>
          <?php
          $rooms = $this->db->get('room')->result_array();
          foreach($rooms as $row):
            ?>
            <option value="
                    <?php echo $row['room_id']; ?>">
                      <?php echo $row['name']; ?>
            </option>
          <?php endforeach; ?>
        </select>
      </div>
      <div class="form-group">
        <select name="teacher_id[]" id="teacher_id" class="form-control select2" style="width: 300px; margin-left: 5px;">
          <option value="">
            <?php echo get_phrase('teacher'); ?>
          </option>
          <?php
          $rooms = $this->db->get('teacher')->result_array();
          foreach($rooms as $row):
            ?>
            <option value="
                    <?php echo $row['teacher_id']; ?>">
                      <?php echo $row['name']; ?>
                      <?php echo $row['email']; ?>
            </option>
          <?php endforeach; ?>
        </select>
      </div>
      <div class="form-group">
        <select name="tutorial_id[]" id="tutorial_id" class="form-control select2" style="width: 100px; margin-left: 5px;">
          <option value="">
            <?php echo get_phrase('tutorial'); ?>
          </option>
          <?php
          $rooms = $this->db->get('tutorialgroup')->result_array();
          foreach($rooms as $row):
            ?>
            <option value="<?php echo $row['tutorialgroup_id']; ?>">
               <?php echo $row['name']; ?>
            </option>
          <?php endforeach; ?>
        </select>
      </div>
      <div class="form-group">
        <select name="mentorgroup_id[]" id="mentorgroup_id" class="form-control select2" style="width: 100px; margin-left: 5px;">
          <option value="">
            <?php echo get_phrase('lab'); ?>
          </option>
          <?php
          $rooms = $this->db->get('mentorgroup')->result_array();
          foreach($rooms as $row):
            ?>
            <option value="<?php echo $row['mentorgroup_id']; ?>">
               <?php echo $row['name']; ?>
            </option>
          <?php endforeach; ?>
        </select>
      </div>
      <div class="form-group">
        <button type="button" class="btn btn-default " title="
                <?php echo get_phrase('remove'); ?>"
                onclick="deleteParentElement(this)" style="margin-left: 10px;">
          <i class="entypo-trash" style="color: #696969;"></i>
        </button>
      </div>
    </div>
  </div>
  <div id="classroutine_entry_append"></div>
  <br>
  <div class="row">
    <center>
      <button type="button" class="btn btn-default" onclick="append_classroutine_entry()">
        <i class="entypo-plus"></i>
        <?php echo get_phrase('add_a_row'); ?>
      </button>
    </center>
  </div>
  <br>
  <br>
  <div class="row">
    <center>
      <button type="submit" class="btn btn-success" id="submit_button">
        <i class="entypo-check"></i>
        <?php echo get_phrase('save_class_routine'); ?>
      </button>
    </center>
  </div>
</div>
<?php echo form_close(); ?>
<script type="text/javascript">

  var blank_classroutine_entry = '';
  $(document).ready(function () {

    blank_classroutine_entry = $('#classroutine_entry').html();
    for ($i = 0; $i
      < 18; $i++) {
      $("#classroutine_entry").append(blank_classroutine_entry);
    }

  });
  function get_sections(class_id) {
    $.ajax(
      {
        url: '<?php echo base_url(); ?>index.php?admin / get_bulkclassroutine_sections / ' + class_id,
        success: function (response)
        {
          jQuery('#section_holder').html(response);
          jQuery('#bulk_add_form').show();
        }
      });
  }


  function append_classroutine_entry()
  {
    $("#classroutine_entry_append").append(blank_classroutine_entry);
  }

  // REMOVING
  function deleteParentElement(n)
  {
    n.parentNode.parentNode.parentNode.removeChild(n.parentNode.parentNode);
  }
</script>

code of controller class

function classroutine_bulk_add($param1 = '')
{
  if($this->session->userdata('admin_login') != 1)
    redirect(base_url(), 'refresh');

  if($param1 == 'create')
  {

    $days = $this->input->post('day');
    $period_ids = $this->input->post('period_id');
    $subject_ids = $this->input->post('subject_id');
    $room_ids = $this->input->post('room_id');
    $teacher_ids = $this->input->post('teacher_id');
    $mentorgroup_ids = $this->input->post('mentorgroup_id');
    $tutorialgroup_ids = $this->input->post('tutorialgroup_id');


    $classroutine_entries = sizeof($room_ids);
    for($i = 0; $i < $classroutine_entries; $i++)
    {
      $data['day'] = $days[$i];
      $data['period_id'] = $period_ids[$i];
      $data['subject_id'] = $subject_ids[$i];
      $data['room_id'] = $room_ids[$i];
      $data['teacher_id'] = $teacher_ids[$i];
      $data['mentorgroup_id'] = $mentorgroup_ids[$i];
      $data['tutorialgroup_id'] = $tutorialgroup_ids[$i];
      $data['class_id'] = $this->input->post('class_id');
      $data['section_id'] = $this->input->post('section_id');
      $data['semester_id'] = $this->input->post('semester_id');
      $data['year'] = $this->db->get_where('settings', array('type' => 'running_year'))->row()->description;

      // validate here, if the row(name, email, password) is empty or not
      if($data['day'] == '' || $data['period_id'] == '' || $data['subject_id'] == '' || $data['teacher_id'] == '' || $data['mentorgroup_id'] == '' ||
        $data['tutorialgroup_id'] == '')
        redirect(base_url().'index.php?admin/', 'refresh');

      $this->db->insert('class_routine', $data);
    }

    $this->session->set_flashdata('flash_message', get_phrase('class_routines_added'));
    redirect(base_url().'index.php?admin/classroutine_bulk_add/', 'refresh');
    //  redirect(base_url() . 'index.php?admin/class_routine_view/' . $this->input->post('class_id') , 'refresh');
  }

  $page_data['page_name'] = 'classroutine_bulk_add';
  $page_data['page_title'] = get_phrase('add_bulk_classroutine');
  $this->load->view('backend/index', $page_data);
}
  • 写回答

1条回答 默认 最新

  • dongxie3963 2017-04-05 15:48
    关注

    I use something like this, using Jason:

    My JS:

    function deletefile(delstring_val,typestring_val,filedirectory_val)
    {
    
        if(r == true)
        {
            $.ajax({
              url: 'delete.php',
              data: {delstring: delstring_val, typestring: typestring_val},
              type: 'POST',
              success: function (response) {
                  alert(response);
                  document.location.href = newURL;            
              },
              error: function () {
                 alert('ERROR deleting the item !!'); 
    
              }
            });
    
        }
        else
        {
            alert('Item deleting was cancel !!');
        }
    }
    

    My html:

    <td> <a href='#' onclick = 'deletefile("<?php echo $basedir."/".$dir."/".$files[$row1];?>","<?php echo $tipo[$row1];?>","<?php echo $dir;?>");'>Delete</a> </td>
    

    In my Delete.php:

    $testetype=$_POST['typestring'];
    

    It works, if you need help, comment that I will try to help.

    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致