使用模态作为部分视图发布codeigniter表单而不传递正确的变量

时间:2016-07-21 14:44:28

标签: javascript jquery ajax twitter-bootstrap codeigniter-3

我正在尝试通过带有是或否按钮的简单模式提交表单。但是,当我单击视图中的按钮时,event_id不会更新,只传递第一个event_id。我假设我需要以某种方式更新传递给模态的event_id;因为它似乎已经加载。我该怎么做?我想也许是设置eventId的onclick函数,但是我对编码很新,不知道如何去做。希望这是有道理的。

这是我的控制器:

function skatersuccess(){
    if (!$this->ion_auth->is_admin())
    {
        $this->session->set_flashdata('message', '<div class="alert alert-info" role="alert">You must be an admin to view this page</div>');
        redirect('/');
    }

    $event_id = $this->input->post('event_id');
    $user_id = $this->input->post('user_id');

    $user_data = array(
            'id'    => 'null',
            'user_id' => $user_id,
            'event_id' => $event_id,
            'is_paid' => 1
        );

    $this->user_event_model->registerskater($user_data);
    redirect('/dashboard/','refresh');
    }

这是我的模特:

public function registerskater($user_data) {
        $this->load->database('hockey');
        $this->db->insert('users_events', $user_data);
    }

这是主视图按钮代码(这会加载弹出模式:

<?php if (($e->user_registered == 1)) : ?>
  <?php $this->load->view('admin/partial/skater_cancel', $e) ?>
  <?php elseif (($e->capacity == $e->registered)): ?>
  <button type="button" class="btn btn-danger btn-block">FULL</button>
  <?php else: ?>
  <?php $this->load->view('admin/partial/skater', $e) ?>
  <?php endif; ?>

这是弹出模式视图:

    <form action="dashboard/skatersuccess" name="" id="login-form" class="form-horizontal" enctype="multipart/form-data" method="POST">

    <button type="button" class="btn btn-primary btn-block" data-title="add_skater" data-toggle="modal" data-target="#add_skater" >SIGN UP AS SKATER</button>

    <!--Pop Up Dialog-->
    <div class="modal fade" id="delete" tabindex="-1" role="dialog" aria-labelledby="edit" aria-hidden="true">
    <div class="modal-dialog">
    <div class="modal-content">
    <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-remove" aria-hidden="true">    </span></button>
    <h4 class="modal-title custom_align" id="Heading">Signup for Game?</h4>
    </div>
    <div class="modal-body">

    <div class="alert alert-danger"><span class="glyphicon glyphicon-warning-sign"></span>Are you sure you want to sign up for game?</div>

    </div>
    <div class="modal-footer ">



    <button type="button" id="btnYES" href="#" name="submit" class="btn btn-success"><span class="glyphicon glyphicon-ok-sign"></span> Yes</button>

    <input id="event_id" type="hidden" class="form-control" name="event_id" value="<?php echo $id; ?>" placeholder="event_id">
        <input id="user_id" type="hidden" class="form-control" name="user_id" value="<?php echo $this->session->userdata('user_id'); ?>" placeholder="user_id">

    <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> No</button>
    </div>
    </div>
    <!-- /.modal-content --> 
    </div>
    <!-- /.modal-dialog --> 
    </div>


</form>

1 个答案:

答案 0 :(得分:0)

我明白了,

<script>
$(document).on("click", ".add_skater", function (e) {

e.preventDefault();

var _self = $(this);

var myEventId = _self.data('id');
$("#EventId").val(myEventId);

$(_self.attr('href')).modal('show');
});
</script>