多个表单验证码信号冲突 [英] multiple form validation codeigniter conflict

查看:238
本文介绍了多个表单验证码信号冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

Codeigniter 2表单在一个页面上,validation_errors问题

我在我的页面中有2个表单。我需要一次验证他们1,但我认为有一个冲突。这里看一下:

I have 2 forms in my page. I need to validate them 1 at a time but I think there is a conflict. Here take a look:

当我提交表单时,两者都显示相同的错误讯息

when I submit either of the form, both of them show the same error message

c $ c> validation_errors()显示消息。如何一次验证表单1?

I use validation_errors() to display the messages. How can I validate the form 1 at a time?

以下是代码

public function update_user_info(){ 
    $this->form_validation->set_rules("firstname","First Name","required");     
    $this->form_validation->set_rules("lastname","Last Name","required"); 
    $this->form_validation->set_rules("middlename","Middle Name","required"); 
    if($this->form_validation->run()===false){ 
        //wrong 
    } 
    else { //correct } 
}


推荐答案


我的解决方案是:

I just encountered the issue. My solution is:

1.首先设置第一个提交按钮name ='update_info'

1.First set the first submit button name = 'update_info'

2.再次设置第二个提交按钮name ='change_password'

2.Secondly set the second submit button name = 'change_password'

3.更改您的update_user_info()。

3.Last change your update_user_info().

public function update_user_info(){ 
    if (isset ($_POST['update_info'])) {
        $this->form_validation->set_rules("firstname","First Name","required");     
        $this->form_validation->set_rules("lastname","Last Name","required"); 
        $this->form_validation->set_rules("middlename","Middle Name","required"); 
        if($this->form_validation->run()===false){ 
            //wrong 
        } 
        else { //correct }             
    }
    else if (isset ($_POST['change_password'])){
        form_validation of your change password
    }

我认为这是解决问题的最简单方法。

I think this is the easiest way to fix your issue.

祝你好运。

这篇关于多个表单验证码信号冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆