将数据从表单传递到另一个表单时的codeigniter表单验证问题

时间:2012-02-07 20:45:16

标签: php codeigniter

我在页面中有一个表单,它将输出数据传递给另一个包含另一个表单的页面。

问题在于,当我尝试浏览第二页时,会显示此页面的验证错误,因为它会从第1页的表单中看到POST数组,因此它不需要相同的输入传递验证错误,它显示验证消息。

以下是第二种形式的控制器中的代码:

function download_application()
{
    //load the libraries
    $this->load->library('form_validation');

    //form validation
    $this->form_validation->set_rules('name', 'name is required', 'required');
    $this->form_validation->set_rules('email', 'email  is required', 'required|valid_email');
    $this->form_validation->set_rules('country', 'country is required', 'required');
    $this->form_validation->set_rules('phone', 'phone is required', 'required');

    if($this->form_validation->run() == FALSE){
        //error in the form
    }else{
        //no error in the form          
    }
}

3 个答案:

答案 0 :(得分:1)

我有两个解决方案作为逻辑我没有写PHP而是逻辑 1.你可以为你的按钮增加价值,在第二页中检查这个值,如果它没有相同的值,那么你没有验证它 2.添加隐藏字段并传递它以在第二页中检查该值

答案 1 :(得分:0)

设置一个变量,将父表单标识为海报,并根据该变量设置或取消设置当前表单的表单验证检查。

答案 2 :(得分:0)

您应该让每个表单都提交给自己,以便相关控制器处理自己的验证。验证通过后,您可以使用URL帮助程序中的redirect()函数或header("Location:...");

将用户重定向到第二个控制器
相关问题