简体   繁体   English

验证成功后,我如何在Codeigniter中重定向页面

[英]After validation sucessfully how i redirect page in codeigniter

I am using codeigniter. 我正在使用codeigniter。 In my project I am trying to do field validation for this I am using bootstrap validator. 在我的项目中,我正在尝试使用Bootstrap验证程序对此进行字段验证。

Bootstrap validator is working well but my problem is that I want after successful validation my form is submitted. Bootstrap验证程序运行良好,但是我的问题是我希望在成功验证后提交表单。 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. 这是我在视图文件中的javascript代码。 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. 我想要验证成功后,再在form标记中指定的路径上提交表单。 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');
       }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM