简体   繁体   English

选择选项未将值传递给Codeigniter中的控制器功能

[英]select option is not passing value to controller function in 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. 我试图使用select2 ajax selectbox(selectbox2.github.io)将所有值保存为数组,但我的控制器类未从codeigniter的视图类中获取任何值,我用普通的文本框替换了select2框,然后正常工作。

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. 1.为什么select2没有将值传递给我的控制器类,或者为什么我的控制器类没有从视图类中获取值。

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. 2.我创建了添加类函数来添加新的select2元素的空白行,当我的页面加载时,添加函数可以正常工作,但是当我试图在单击事件上调用相同的函数时,屏幕上什么也没有出现。

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);
}

I use something like this, using Jason: 我使用Jason使用类似的方法:

My JS: 我的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: 我的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: 在我的Delete.php中:

$testetype=$_POST['typestring'];

It works, if you need help, comment that I will try to help. 它可以正常工作,如果您需要帮助,请评论我将尽力提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM