Form validation with BoostrapValidator - cifan - 01-30-2019
Hi All,
I have created a form like:
Code: <form action="<to_controller_method>" method="post" id="form">
I'm using BootstrapValidator (of course with Bootstrap 3) to validate some fields in this form.
Although I have managed to trigger the validation errors upon a field input error, however when I push the submit button (with no field errors) the form can't be submitted (submit button is being disabled). However, when I update a validated field the form is submitted.
I wonder why the form can't be submitted when the submit button is being pushed for the first time.
RE: Form validation with BoostrapValidator - php_rocs - 01-30-2019
@cifan,
I have run into a problem similar to this one and I had to go through each input field until I found the one that was throwing the error.
Is it possible to see more code? What validated field must you update in order for the form to be submitted?
RE: Form validation with BoostrapValidator - cifan - 01-31-2019
@php_rocs
The form is:
Code: <form action="<?php echo site_url('contact/contact_form'); ?>" method="post" id="testform">
<br /><br />
<div class="card">
<div class="card-header">Personal Info</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<small class="form-text text-muted">First Name</small>
<?php echo form_input(array('class'=>'form-control', 'id'=>'first_name', 'name'=>'first_name'));?>
</div>
<small class="form-text text-muted">Gender</small>
<div class="form-group">
<?php echo form_dropdown('gender', array('Male'=>'Male', 'Female'=>'Female'), 'Male', 'class="form-control" id="gender"');?>
</div>
<div class="form-group">
<small class="form-text text-muted">Email</small>
<?php echo form_input(array('class'=>'form-control', 'id'=>'email', 'name'=>'email'));?>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<small class="form-text text-muted">Last Name</small>
<?php echo form_input(array('class'=>'form-control', 'id'=>'last_name', 'name'=>'last_name','size'=>25));?>
</div>
<div class="form-group">
<small class="form-text text-muted">Phone</small>
<?php echo form_input(array('class'=>'form-control', 'id'=>'phone', 'name'=>'phone', 'size'=>25));?>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button type="submit" name="submit" class="btn btn-primary pull-left">Submit Form</button>
</div>
</div>
</form>
and the validation is
Code: // Form Validation
$('#testform').bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
first_name: {
message: 'The username is not valid',
validators: {
notEmpty: {
message: 'The username is required and cannot be empty'
},
stringLength: {
min: 6,
max: 30,
message: 'The username must be more than 6 and less than 30 characters long'
},
regexp: {
regexp: /^[a-zA-Z0-9_]+$/,
message: 'The username can only consist of alphabetical, number and underscore'
}
}
},
email: {
validators: {
notEmpty: {
message: 'The email is required and cannot be empty'
},
emailAddress: {
message: 'The input is not a valid email address'
}
}
}
}
});
});
When I update the email field, then the form can be submitted.
|