Welcome Guest, Not a member yet? Register   Sign In
form validation
#1

[eluser]Ngulo[/eluser]
hi everyone i'm using these code to do the user registration without 2 distinct views ,but to do all in the same view(Home_view):

controller:
Code:
class Home extends Controller
{
    
    
    function index()
    {
      $this->load->helper(array('form','url'));
      $this->load->library('Validation');
      $rules['username']= "required|min_length[5]|max_length[12]";
      $rules['password']= "required|matches[confpassword]";
      $rules['confpassword']= "required";
      $rules['email'] = "required|valid_email";

      $this->validation->set_rules($rules);
      $fields['username']    = 'Username';
    $fields['password']    = 'Password';
    $fields['confpassword']    = 'Password Confirmation';
    $fields['email']    = 'Email Address';
        $this->validation->set_fields($fields);
        if($this->validation->run() == FALSE && isset($fields) )
        {$this->load->view('Home_view');}
        else{
            $data['messaggio_conferma']="registration ok";
            $this->load->view('Home_view',$data);

        }
    
    
    }
}

and home_view:
Code:
<?php echo form_open('home');?>
        Username
        <input type="text" name="username"><br>
        <?php echo $this->validation->username_error; ?>

            
        Password
        <input type="password" name="password"><br>
        
            <?php echo $this->validation->password_error; ?>
        Password Conferma
        <input type="password" name="confpassword"><br>
        <?php echo $this->validation->confpassword_error; ?>
            
        Email
        <input type="text" name="email"><br>

        
           <?php echo $this->validation->email_error; ?>

        <input type="submit" name="login" value="login"><br>
         <?php  if($this->validation->run() == TRUE){echo $messaggio_conferma;}?>

        </form>

it works really great Wink

is not definitive code i have to upgrade and i have some questions about it

why does form_validation library doesn't works as the validation one? i can't use that Sad

again, i would like to know how to set my personal error_messages's text for any error input name?

any suggest for my code? do you know a better way to do the registration in the same view page?

thanks to all Wink
#2

[eluser]2think[/eluser]
Not sure if this helps but since you said you need to upgrade and since forms are made a lot easier by this library, maybe you want to take a look at this excellent library that helps with forms here:

http://ellislab.com/forums/viewthread/107861/
#3

[eluser]Ngulo[/eluser]
thanks a lot but for now i'm able only to say hello world in CI so i have to understand the framework's basics , later i will try new features

but now i'm still trying to configure my own error_messages on each input

how can i do to have my own messages displaying on each name error(username_error,password_error,etc ...)?

joking, maybe :
$this->validation->username_error('hello this is username error');??




thanks again Wink
#4

[eluser]danmontgomery[/eluser]
Any reason you're using validation instead of form_validation? validation is deprecated, and shouldn't be used. Either way, you can use set_message().

http://ellislab.com/codeigniter/user-gui...tingerrors

Code:
$this->form_validation->set_message('username', 'This is my username error');
#5

[eluser]Ngulo[/eluser]
hi noctrum , i was saying before that if i use this same code , loading form_validation instead of validation library's ,the apps doesn't works :O

i don't know why ,maybe when i make the changes to load the other library i forget something important ,i really don't know :O

anyway thanks a lot for the example to change form errors ,was all i need to know Wink




Theme © iAndrew 2016 - Forum software by © MyBB