Welcome Guest, Not a member yet? Register   Sign In
Form validation don't work
#1

Hi this is my form user/register :
Code:
<!DOCTYPE html>

<html>
   <head>
       <meta charset="UTF-8">
       <title></title>
   </head>
   <body>
       <h1>Register</h1>
       <?php   echo form_open('user/register'); ?>
       
       <input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>">

       <p>
           <?= form_label('Email*:' ,'email') ;?>
           <?= form_input('email' ,set_value('email'),'id="email_id"') ;?>
           
       </p>
       
       <p>
           <?= form_label('Username:' ,'username') ;?>
           <?= form_input('username' ,set_value('username'),'id="username_id"') ;?>
           
       </p>
           
       <p>
           <?= form_label('Password*' ,'password') ;?>
           <?= form_input('password' ,'','id="password_id"') ;?>
           
       </p>
       
              <p>
           <?= form_label('Repeat Password*' ,'repeat_password') ;?>
           <?= form_input('password' ,'','id="password_id"') ;?>
           
       </p>
       
           <?= form_submit('submit','Login') ;?>
           <?= form_close();?>
       
       
       <?php  echo form_close();?>
       <div><?= validation_errors(); ?></div>

   </body>
</html>

This is my controller function :


Code:
function register(){
     
      $this->load->library('form_validation');
      $this->form_validation->set_rules('email','Email','required|valid_email', array('required' => 'Inserisci la mail','valid_email'=>'la mail deve essere valida'));
      $this->form_validation->set_rules('password','Password','required|min_length[6]');    
      $this->form_validation->set_rules('repeat_password','Password Confirmation','required');    
      $this->form_validation->set_rules('username','Username','min_length[6]|max_length[12]',array('min_length'=>'Lunghezza minima 6 caratteri', 'max_length'=>'Lunghezza massima 12 caratteri'));
       
       $this->load->model('user_model');
       
       $data=[];
       
       if($this->form_validation->run()){
           
         
         
          $res=$this->user_model
          ->registerNewUser(
              $this->input->post('email'),
              $this->input->post('username'),
              $this->input->post('password'),
              $this->input->post('repeat_password')
          );
         
          $data['res']=$res;
         
          if($res!=FALSE){
             $_SESSION['user_id']=$res->id;
             redirect('user/prova');
          }
         
       
       }
       
       $data['errors']    = $this->user_model->errors;
       
       $data['messages']  = $this->user_model->messages;
       
       $this->load->view('user/register', $data);
   }
     


But if i insert email  and password i have this error :

The Password field is required.

if i insert password and password_repeat to i have this error :

The Password Confirmation field is required.


this is a test application :

http://lemuria.altervista.org/user_codei...r/register
Reply


Messages In This Thread
Form validation don't work - by pippuccio76 - 06-20-2017, 12:03 PM
RE: Form validation don't work - by Wouter60 - 06-20-2017, 12:54 PM
RE: Form validation don't work - by Martin7483 - 06-20-2017, 01:12 PM



Theme © iAndrew 2016 - Forum software by © MyBB