Welcome Guest, Not a member yet? Register   Sign In
Form loses style upon validation process
#1

[eluser]John Lopez[/eluser]
Hi guys, I was just playing around with form validation, but I really really can't figure out why my form loses its style when the validation process starts to run. I have my blocks of code below, hope you can help me out:

Controller
Code:
class Home_controller extends CI_Controller {
    
    function index () {
        $this->load->view('home_view');
    }
    
    function form_validate () {
        $this->load->library('form_validation');
        $this->load->library('encrypt');
        
        # set validation rules
        $this->form_validation->set_rules('username', 'username', 'trim|required');
        $this->form_validation->set_rules('password', 'password', 'trim|matches[passwordconf]|min_length[7]|required|sha1');
        $this->form_validation->set_rules('passwordconf', 'passwordconf', 'trim|matches[password]|min_length[7]|required|sha1');
        $this->form_validation->set_rules('email', 'email', 'trim|valid_email|required');
        $this->form_validation->set_rules('fname', 'first name', 'trim');
        $this->form_validation->set_rules('lname', 'last name', 'trim');
        
        if ($this->form_validation->run() == TRUE) {
            echo '<h1>Thank you for registering!</h1>';
        } else {
            $this->load->view('home_view');
        }
        
    }
    
}

View
Code:
&lt;?php $this->load->view('home_header'); ?&gt;
<h1>Tutorial: Simple Registration</h1>

&lt;?php
# set attributes of form components

# form attributes
$form_attrib = array (
    'id'            => 'form',
    'name'          => 'form',
    'method'        => 'post'
);

# username field attributes
$username_attrib = array (
    'id'            => 'username',
    'class'         => 'input_field',
    'name'          => 'username',
    'placeholder'   => 'Desired username'
);

# password field attributes
$password_attrib = array (
    'id'            => 'password',
    'class'         => 'input_field',
    'name'          => 'password',
    'placeholder'   => 'Desired password'
);

# password confirmation field attributes
$passwordconf_attrib = array (
    'id'            => 'passwordconf',
    'class'         => 'input_field',
    'name'          => 'passwordconf',
    'placeholder'   => 'Confirm password'
);

# email field attributes
$email_attrib = array (
    'id'            => 'email',
    'class'         => 'input_field',
    'name'          => 'email',
    'placeholder'   => 'Existing email address'
);

# first name field attributes
$fname_attrib = array (
    'id'            => 'fname',
    'class'         => 'input_field',
    'name'          => 'fname',
    'placeholder'   => 'First name'
);

# last name field attributes
$lname_attrib = array (
    'id'            => 'lname',
    'class'         => 'input_field',
    'name'          => 'lname',
    'placeholder'   => 'Last name'
);

# submit button attributes
$submit_attrib = array (
    'id'            => 'submit',
    'name'          => 'submit',
    'value'         => 'Submit'
);
?&gt;

&lt;?php echo form_open('home_controller/form_validate', $form_attrib); ?&gt;
    &lt;?php echo form_input($username_attrib); ?&gt;
    &lt;?php echo form_error('username'); ?&gt;
    
    &lt;?php echo form_password($password_attrib); ?&gt;
    &lt;?php echo form_error('password'); ?&gt;

    &lt;?php echo form_password($passwordconf_attrib); ?&gt;
    &lt;?php echo form_error('passwordconf'); ?&gt;

    &lt;?php echo form_input($email_attrib); ?&gt;
    &lt;?php echo form_error('email'); ?&gt;
    
    &lt;?php echo form_input($fname_attrib); ?&gt;
    &lt;?php echo form_error('fname'); ?&gt;

    &lt;?php echo form_input($lname_attrib); ?&gt;
    &lt;?php echo form_error('lname'); ?&gt;

    &lt;?php echo form_submit($submit_attrib) ?&gt;
&lt;?php echo form_close(); ?&gt;
&lt;?php $this->load->view('home_footer'); ?&gt;

Header
Code:
<!DOCTYPE HTML>

&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;CI Series : Form Login&lt;/title&gt;
        
        &lt;link rel="stylesheet" href="css/style.css" media="screen" /&gt;
    &lt;/head&gt;
    &lt;body&gt;

Footer
Code:
&lt;/body&gt;
&lt;/html&gt;

*** The default run displays the styling perfectly. I guess it's being eaten by the forms, huh? :gulp:


Messages In This Thread
Form loses style upon validation process - by El Forum - 06-25-2011, 01:52 AM
Form loses style upon validation process - by El Forum - 06-25-2011, 01:56 AM
Form loses style upon validation process - by El Forum - 06-25-2011, 02:25 AM
Form loses style upon validation process - by El Forum - 06-25-2011, 02:42 AM
Form loses style upon validation process - by El Forum - 06-25-2011, 03:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB