Welcome Guest, Not a member yet? Register   Sign In
Can't seem to get this to work.
#1

[eluser]gork7478[/eluser]
I have a problem no matter what I do I can't seem to get form_validation to work.

Here's my code. This is a method in my main controller.

Code:
public function register()
    {
        $this->load->library('phpass');
        
        $this->form_validation->set_rules('fname','First Name','trim|require');
        $this->form_validation->set_rules('lname','Last Name','trim|require');
        $this->form_validation->set_rules('email','Email','trim|require');
        $this->form_validation->set_rules('password','Password','trim|require');
        $this->form_validation->set_rules('conf_password','Comfirm Password','trim|require');
        
        if($this->form_validation->run() == FALSE){
              $data['main_content'] = 'main/register';
              $this->load->view('template', $data);
        }
        else{
            echo 'Success';  
        }
    }

Here's the view with the form. The form pulls up fine and it even posts but as you can see I have some rules and it's says success no matter if the fields are blank or not.

Code:
<?php
    $fname = array(
        'id' => 'fname',
        'name' => 'fname',
        'maxlength' => 45,
        'value' => set_value('fname')
    );
    $lname = array(
        'id' => 'lname',
        'name' => 'lname',
        'maxlength' => 45,
        'value' => set_value('lname')
    );
    $email = array(
        'id' => 'email',
        'name' => 'email',
        'maxlength' => 45,
        'value' => set_value('email')
    );
    $password = array(
        'id' => 'password',
        'name' => 'password',
        'maxlength' => 45
    );
    $conf_password = array(
        'id' => 'conf_password',
        'name' => 'conf_password',
        'maxlength' => 45
    );
?>
<h1>Register Form</h1>
&lt;?php
echo form_open(base_url() .'main/register', array('class' => 'reg_form'));

echo form_label('First Name', 'fname');
echo form_input($fname);
echo form_error('fname','<div class="error"','</div>');

echo form_label('Last Name', 'lname');
echo form_input($lname);
echo form_error('lname','<div class="error"','</div>');

echo form_label('Email', 'email');
echo form_input($email);
echo form_error('email','<div class="error"','</div>');

echo form_label('Password', 'password');
echo form_password($password);
echo form_error('password','<div class="error"','</div>');

echo form_label('Confirm Password', 'conf_password');
echo form_password($conf_password);
echo form_error('conf_password','<div class="error"','</div>');

echo form_submit('register', 'Register');

echo form_close();
?&gt;
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

There is no such rule as "require". The rule is "required".

If the validation class cannot find a rule, it will just continue, and not fail. Most of the CodeIgniter libraries are built to be robust, and not to throw errors all over the place. Granted, it can be a pain when a problem like this crops up, but it helps keep your production app error-free (in the sense of framework-related PHP errors).
#3

[eluser]gork7478[/eluser]
Thanks for the help




Theme © iAndrew 2016 - Forum software by © MyBB