0

似乎有很多关于表单验证的问题,但没有一个回答我的问题。

除非我遗漏了一些明显的东西,否则我的表单验证将不会运行,但仅在某个页面上,所有其他页面都很好。

这是问题代码:

public function activate($code = '')
    {
        // This function lets a user activate their account with the code or link they recieved in an email
        if($code == '' || isset($_POST[''])){
            $form = '';
            $this->load->library('form_validation');
            $this->load->helper('form');

            if ($this->form_validation->run() == FALSE){
                // No code, so display a box for them to enter it manually
                $this->form_validation->set_rules('activation_code', 'Activation Code', 'trim|required|xss_clean|integer');

                $form .= validation_errors();
                $form .= form_open_multipart('user/activate', array('class' => 'formee'));

                $form .= form_label('Enter your activation code below and click \'Activate\' to start using your account. If you need a hand please contact live chat.', 'activation_code');
                $form .= form_input(array('name' => 'activation_code'));

                $data = array(
                    'name'        => 'submit',
                    'value'       => 'Activate',
                    'class'       => 'right',
                    'style'       => 'margin-top:10px;',
                );

                $form .= form_submit($data);
                $form .= form_close();
            }else{
                $form .= "form run";
            }
        }else{
            // Code recieved through the GET or POST variable XSS clean it and activate the account
        }

        $data = array(
            'title' => $this->lang->line('activate_title'),
            'links' => $this->gen_login->generate_links(),
            'content' => $form
        );
        $this->parser->parse('beer_template', $data);
    }

您可以在此处查看页面:http://77.96.119.180/beer/user/activate

您可以在此处查看表单验证:http://77.96.119.180/beer/user/register

任何人都可以帮忙吗?

4

1 回答 1

3

运行后调用 set_rules :

if ($this->form_validation->run() == FALSE){
  // No code, so display a box for them to enter it manually
  $this->form_validation->set_rules('activation_code', 'Activation Code', 'trim|required|xss_clean|integer');

但应该是之前:

$this->form_validation->set_rules('activation_code', 'Activation Code', 'trim|required|xss_clean|integer');
if ($this->form_validation->run() == FALSE){
}
于 2012-06-22T12:06:50.343 回答