刚开始编码;使用codeigniter和bootstrap。我试图通过一个带有是或否按钮的简单模态提交表单。但是,当我单击视图中的按钮时,模态会立即打开并关闭。数据发布到数据库但是,我希望用户先单击“是”或“否”框。
这是我的控制器:
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 class="btn btn-primary btn-block" data-title="Delete" data-toggle="modal" data-target="#delete" >SIGN UP AS SKATER</button></p></td
<!--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>
答案 0 :(得分:0)
因为按钮位于暂时只是获取同一页面的表单中。
用此
替换您的按钮<button type="button" class="btn btn-primary btn-block" data-title="Delete" data-toggle="modal" data-target="#delete" >
SIGN UP AS SKATER
</button>