I am using codeigniter. In my project I am trying to do field validation for this I am using bootstrap validator.
Bootstrap validator is working well but my problem is that I want after successful validation my form is submitted. Now when I click on the submit button after successful validation then it still perform nothing action.
I want after validation when I click on submit button then it will move on the function which is written in my controller.
Here is code of my view file:
<form class="" data-toggle="validator" role="form" id="sms_form" method="Post" action="<?php echo site_url('SMS/sendIndividualMsg/'.$row->pro_id)?>">
<div class="col-md-12">
<div class="form-group">
<label for ="message"><strong>Message</strong></label>
<textarea class="form-control" id="comment_body" name="message" placeholder=" Your Message"></textarea>
<!-- <span class="text-danger"><?php echo form_error("message"); ?></span> -->
</div>
<div>
<!-- <button type="button" class="btn btn-default submit send_enquiry_btn"> Send Message</button> -->
<?php echo form_submit(['name' => 'submit' ,'class' => 'btn btn-default' , 'value' => 'Send Message']); ?>
</div>
</div>
Here is my javascript code in view file. In this code I am doing form field validation. I want when this validation is successful then form is submitted on path which is given in the form tag. Which is a name of function which is written in the controller:
$('#sms_form').bootstrapValidator({
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
message:{
validators: {
regexp: {
regexp: /^[a-zA-Z0-9_\.\s]+$/,
message: 'The message can only consist of alphabetical, number, dot and underscore'
},
notEmpty: {
message: 'Please supply your message'
}
}
}
}
});
This is my function which is written in controller: I want to move on this controller after successful validation. Please help me how i solve this problem.
public function sendIndividualMsg($pro_id){
}
Please help me how i solve this problem. I am doing final year project please help me how I redirect this page:
You need to add code for redirection in your controller file. For that please check below function.
if ($this->form_validation->run() == FALSE) {
**"Code for validation error"**
}
else
{
if ($this->input->post('button_name')) {
$result = $this->Name_of_model->name_of_function('Pass any arguments if function needed.');
if($result){
redirect('page name where you want to redirect');
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.