form_validation-> set_rules()在代码点火器中无法正常工作

时间:2016-01-24 04:39:28

标签: php html codeigniter validation registration

我是代码点火器的新手,并尝试在代码点火器中构建登录和注册表单。到目前为止登录是可以的,但注册表格不提供所需。我按照视频教程,但它没有成功。当我手动调试代码时,我意识到$ this-> form_validation-> set_rules()不起作用。 请帮帮我。

视图

    <form action="<?php echo base_url();?>LoginController/Register" method="get">
          <p><span id="sprytextfield1">
            <label for="tn">Full Name</label>
            <input class="form-control" input type="text" name="full_name" placeholder="Please Enter Your Full Name" style="width:50%" ><?php echo form_error('full_name'); ?>
            <span class="textfieldRequiredMsg"> </span></span> <span id="sprytextfield2">
            <label for="tjt">Designation  <?php echo form_error('des'); ?><br>
              <br>
              <input type="radio" name="des" value="pm">
            Project Manager                     
            <input type="radio" name="des" value="ceo">
            CEO<br>
            <input type="radio" name="des" value="dev">
            Devoloper                       </label>
            </span></p>
          <p><span>                 <span class="textfieldRequiredMsg"></span></span> <span id="sprytextfield3">
          <label for="te">Email</label>
            <input class="form-control" input type="text" name="email" placeholder="Please Enter Your Email" style="width:50%" ><?php echo form_error('email'); ?>
            <span class="textfieldRequiredMsg"></span></span> <span id="sprytextfield4">
              <label for="tc">Company</label>
              <input class="form-control" input type="text" name="company" placeholder="Please Enter Your Company Name" style="width:50%" ><?php echo form_error('company'); ?>
              <span class="textfieldRequiredMsg"></span></span> <span id="sprytextfield5">
            <label for="tun">User Name</label>
            <input class="form-control" input type="text" name="user_name" placeholder="Please Enter Your User Name" style="width:50%" ><?php echo form_error('user_name'); ?>
            <span id="sprytextfield6">
              <label for="tpw">Password</label>
              <input class="form-control" input type="password" name="password" placeholder="Please Enter Your Password" style="width:50%" ><?php echo form_error('password'); ?>
              <span class="textfieldRequiredMsg"></span></span> <span id="sprytextfield7">
                <label for="tpw2"> Confirm Password</label>
                <input class="form-control" input type="password" name="cpassword" placeholder="Please Re Enter Your Password" style="width:50%" ><?php echo form_error('cpassword'); ?>
                <span class="textfieldRequiredMsg"></span></span>                 </p>
          <table width="385"  cellspacing="50px">
            <tr>
              <th width="75"> <a href="<?php echo base_url();?>LoginController/Register"><button type="submit" class="btn btn-lg btn-primary"method="post">Create Account</button></a>
            </th>
              <th width="154"> <input name="Reset" type="reset" class="btn btn-lg btn-primary" >
            </th>
          </tr>
        </table>
          <p>&nbsp;</p>
        </form>

控制器

function Register(){
    $this->load->library('form_validation');
    $this->load->helper(array('form', 'url'));

    //Validation Rules
    $this->form_validation->set_rules('full_name','Full Name','trim|required');
    $this->form_validation->set_rules('email','Email Address','trim|required|valid_email|callback_check_mail_Exists');
    $this->form_validation->set_rules('company','Company','trim|required');
    $this->form_validation->set_rules('user_name','Username','trim|required|min_length[4]|callback_check_user_Exists');
    $this->form_validation->set_rules('password','Password','trim|required|min_length[8]');
    $this->form_validation->set_rules('cpassword','Password Confirmation','trim|required|matches[password]');
    $this->form_validation->set_message('check_user_Exists', 'Username already exists. Please select another');
    $this->form_validation->set_message('check_mail_Exists', 'E-mail already registerd.');
    if($this->form_validation->run()==false){
        $this->load->view('SignUp');
    }else{
        $this->load->model('MembershipModel');
        if($this->MembershipModel->create_member()){
            $data['account_created']='Your account has been created <br/><br/>';
            $this->load->view('loginform',$data);
        }else{
            $this->load->view('SignUp');
        }
    }

}

模型

function create_member(){
        $username=$this->input->post('user_name');

        $new_member=array(
            'full_name' => $this->input->post('full_name'),
            'e-mail' => $this->input->post('email'),
            'company' => $this->input->post('company'),
            'user_name' => $this->input->post('user_name'),
            'pwd' => md5($this->input->post('password')),
            'designation' => $this->input->post('des')
        );

        $insert=$this->db->insert('user',$new_member);
        return $insert;
    }

    function check_mail_Exists($email){
        $this->db->where('e-mail',$email);
        $result=$this->db->get('user');

        if($result->num_rows>0){
            return false;
        }else{
            return true;
        }
    }

请帮帮我

2 个答案:

答案 0 :(得分:1)

put method =&#34; post&#34;在您的视图文件中

答案 1 :(得分:0)

试试这个

视图

response.setHeader("myHeader", "hey there");
response.sendRedirect("redirect.jsp");