我遇到了奇怪的问题。
我的提交按钮仅在重新编辑任何字段时才有效。如果我按下提交按钮变得禁用。然后我需要重新编辑日期字段(任何字段都需要验证),然后我可以提交表单。
注意:即使重新编辑任何字段,也无法在jsfiddle上工作(提交按钮仍然禁用)。但是重新编辑适用于我的项目!
这是我的代码Jsfiidle Link
$(document).ready(function() {
$('#reportForm')
.bootstrapValidator({
// Only disabled elements are excluded
// The invisible elements belonging to inactive tabs must be validated
excluded: [':disabled'],
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
reportStartDate: {
validators: {
notEmpty: {
message: 'Please select Date'
}
}
},
reportEndDate: {
validators: {
notEmpty: {
message: 'Please select Date'
}
}
}
}
})
// Called when a field is invalid
.on('error.field.bv', function(e, data) {
// data.element --> The field element
var $tabPane = data.element.parents('.tab-pane'),
tabId = $tabPane.attr('id');
$('a[href="#' + tabId + '"][data-toggle="tab"]')
.parent()
.find('i')
.removeClass('fa-check')
.addClass('fa-times');
})
// Called when a field is valid
.on('success.field.bv', function(e, data) {
// data.bv --> The BootstrapValidator instance
// data.element --> The field element
var $tabPane = data.element.parents('.tab-pane'),
tabId = $tabPane.attr('id'),
$icon = $('a[href="#' + tabId + '"][data-toggle="tab"]')
.parent()
.find('i')
.removeClass('fa-check fa-times');
// Check if the submit button is clicked
if (data.bv.getSubmitButton()) {
// Check if all fields in tab are valid
var isValidTab = data.bv.isValidContainer($tabPane);
$icon.addClass(isValidTab ? 'fa-check' : 'fa-times');
}
});
});
花了半天的时间终于找到了解决方案。问题是按钮的"名称"属性。引导验证在理解表单是否提交时遇到问题!
当我使用以下方式不起作用!
<button type="submit" class="btn btn-warning" name="submit" value="showReport">Show Report</button>
使用php代码
if (isset($_POST['submit']))
溶液!
<button type="submit" class="btn btn-warning">Show Report</button>
使用php代码
($_SERVER['REQUEST_METHOD'] == 'POST')
我遇到了同样的问题,但意识到我的目标是容器div 而不是表单标签。可能会为某人节省一些时间。