-1

我过去使用过 codeigniter,但我正在建立一个社交网络,并且正在注册。我已经自动加载了表单和表单验证助手。我有一个用于我的用户控制器/注册功能的表单,并且我设置了验证规则,但它忽略了它们并继续到下一页。我不能为我的生活弄清楚为什么。任何帮助表示赞赏..代码和规则不完整(显然)但验证应该在这一点上工作

看法

                <?php echo validation_errors('<p class="error">'); ?>
                <?php echo form_open('user/register/1'); ?>
                <?php echo form_hidden('register_id', $randomcode); ?>
                <?php echo form_label('First Name', 'first_name'); ?>
                <?php echo form_input('first_name',set_value('first_name')); ?>
                <br />
                <?php echo form_label('Last Name', 'last_name'); ?>
                <?php echo form_input('last_name',set_value('last_name')); ?>
                <br />
                <?php echo form_label('Gender', 'gender:'); ?>
                <?php echo form_radio('gender', 'male'); ?> Male
                <?php echo form_radio('gender', 'female'); ?> Female
                <br />
                <?php echo form_label('Date of Birth:', 'birthdate'); ?>
                <?php echo form_date('birthdate'); ?>
                <br />
                <?php echo form_label('Zipcode:', 'zipcode'); ?>
                <?php echo form_input('zipcode',set_value('zipcode')); ?>
                <br />
                <?php echo form_label('Email:', 'email'); ?>
                <?php echo form_email('email',set_value('email')); ?>
                <br />
                <?php echo form_label('Password', 'password'); ?>
                <?php echo form_password('password'); ?>
                <br />
                <?php echo form_label('Confirm', 'password2'); ?>
                <?php echo form_password('password2'); ?>
                <br />
                <?php
                $data = array(
                    'name'        => 'submit',
                    'class'       => 'big-blue-btn',
                    'value'       => 'Sign Up'
                    );
                ?>
                <?php echo form_submit($data); ?>
            <?php echo form_close(); ?>

控制器

public function register($step){
    if($step == 1){
        $this->form_validation->set_rules('first_name', 'first_name', 'required');
                    $this->form_validation->set_rules('last_name', 'last_name', 'required');

        if($this->form_validation->run() == FALSE){
            //Views
            $data['main_content'] = 'public/user/register1';
            $this->load->view('public/template', $data);
        } else {
            //Post values to array
            $data = array(
                    'register_id' => $this->input->post('register_id'),
                    'first_name' => $this->input->post('first_name'),
                    'last_name' => $this->input->post('last_name'),
                    'gender' => $this->input->post('gender'),
                    'birthdate' => $this->input->post('birthdate'),
                    'zipcode' => $this->input->post('zipcode'),
                    'email' => $this->input->post('email'),
                    'password' => $this->input->post('password'),
                    'password2' => $this->input->post('password2')
                );

            //Send input to model
            $this->User_model->register1($data);

            $data['show_sidebar'] = FALSE;
        }

    } elseif($step == 2){
        //Send input to model
        $this->User_model->register2($data);

    } elseif($step == 3){
        //Send input to model
        $this->User_model->register3($data);
    }

}
4

1 回答 1

0

查看您的代码,您的第一个 if 缺少右括号。

于 2013-04-25T21:41:43.717 回答