Royertan Royertan - 6 months ago 22
Javascript Question

Validator accepts submit only when re-editing field (include PHP)

I am having strange problem.

My submit button only works if I reedit any field.
If i press submit button becoming disable.
Then i need to reedit date field (any field require validation) then I can submit the form.

Note:Even reediting any field,didn't work on jsfiddle(submit button still disable).But reediting works on my project!

Here is my code
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');
}
});
});

Answer

After spending half of my day finally found solution.The problem was 'name' attribute for button.Bootstrap validation having problem to understand form submitted or not!

When I use following way doesn't work!

<button type="submit" class="btn btn-warning" name="submit" value="showReport">Show Report</button>

With php code

if (isset($_POST['submit']))

Solution!

<button type="submit" class="btn btn-warning">Show Report</button>

With php code

($_SERVER['REQUEST_METHOD'] == 'POST')
Comments