我有这个表单,允许你选择或添加一个选项到下拉字段,问题是当你单击添加选项,它调用模式,但它也提交整个表单,但我把一个必需的标签输入字段,因此除非已完成,否则它不会真正传递表单
以下表格:
<div class="col-lg-12">
<form action="<?php echo base_url(); ?>products/purchase" role="form" accept-charset="utf-8" method="post">
<div class="form-group">
<div class="col-lg-12">
<label class="control-label">Name</label>
<input type="text" name="name" class="form-control inline" required>
</div>
</div>
<div class="form-group">
<div class="col-lg-10">
<label class="control-label">Class</label>
<div class="input-group">
<select name="class_ID" class="form-control" required>
<option value="">Select Class</option>
<?php if(!empty($cls)){
if (is_array($cls)){
foreach ($cls as $row) {?>
<option value="<?php echo $row['class_id']?>"><?php echo $row['class_Name']; ?></option>
<?php }
}
}
else{ ?>
<option value=""></option>
<?php }?>
</select>
<span class="input-group-btn">
<button class="btn btn-theme" data-toggle="modal" data-target="#addClass"><i class="fa fa-plus"></i></button>
</span>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-12 pull-right">
<input type="submit" class="btn btn-success pull-right" value="Order" style="margin-left:5px;">
</form>
<a href="<?php echo base_url()?>purchases" class="btn btn-default pull-right">Back</a>
</div>
</div>
</div>
模态:
<div class="modal fade" id="addClass" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="vertical-alignment-helper">
<div class="modal-dialog vertical-align-center">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Add New Product Classification</h4>
</div>
<div class="modal-body">
<form action="<?php echo base_url(); ?>products/add_class" method="post" accept-charset="utf-8" role="form">
<div class="form-group">
<div class="col-lg-6">
<label for="class_Name">Classification Name</label>
<input type="text" name="class_Name" class="form-control">
</div>
</div>
<div class="form-group">
<div class="col-lg-3">
<label for="is_active">Enabled</label>
<select name="is_active" class="form-control">
<option value="1">Yes</option>
<option value="0">No</option>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input type="submit" class="btn btn-success" value="ADD">
</form>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
可能是因为使用了两次btn-success成功,你在打开模态时点击它并在模型页脚的底部触发它
答案 1 :(得分:0)
平衡你的html标签 即对于每个打开的标签,必须存在一个封闭的标签,并且也必须以相同的顺序存在。
在你的模态中,你在关闭表单标记之前关闭的div中打开表单标记。某些浏览器可能会自动关闭此标记,因此单击提交按钮将传播到主窗体。
更改为
<div>
<form>
</form>
</div>
在.modal-dialog
之前打开你的表单答案 2 :(得分:0)
更改
<button> to <a> or you can tell <button type="button"> that it's button and should only do what button supposed to do which is not to submit the form
w3schools.com/tags/att_button_type.asp
- Shehary