[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:
<?php $this->load->view('home_header'); ?>
<h1>Tutorial: Simple Registration</h1>
<?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'
);
?>
<?php echo form_open('home_controller/form_validate', $form_attrib); ?>
<?php echo form_input($username_attrib); ?>
<?php echo form_error('username'); ?>
<?php echo form_password($password_attrib); ?>
<?php echo form_error('password'); ?>
<?php echo form_password($passwordconf_attrib); ?>
<?php echo form_error('passwordconf'); ?>
<?php echo form_input($email_attrib); ?>
<?php echo form_error('email'); ?>
<?php echo form_input($fname_attrib); ?>
<?php echo form_error('fname'); ?>
<?php echo form_input($lname_attrib); ?>
<?php echo form_error('lname'); ?>
<?php echo form_submit($submit_attrib) ?>
<?php echo form_close(); ?>
<?php $this->load->view('home_footer'); ?>
Header
Code:
<!DOCTYPE HTML>
<html>
<head>
<title>CI Series : Form Login</title>
<link rel="stylesheet" href="css/style.css" media="screen" />
</head>
<body>
Footer
Code:
</body>
</html>
*** The default run displays the styling perfectly. I guess it's being eaten by the forms, huh? :gulp: