[eluser]the future darlo manager[/eluser]
This is causing me a few problems. Just wondering if I'm missing something really easy. I like to show my validation errors before the form but wrap them in a styled div class. Basically something like the below...
Code:
<div class="errors">
Error with the username field
Error with the password field
</div>
I know I can used $this->validation->set_error_delimiters('<div class="error">', '</div>'); if I wanted to but this obviously wraps the div around each error and not all of them in one go. Any ideas? My controller and view is shown below...
Code:
<?php
class Welcome extends Controller {
function Welcome()
{
parent::Controller();
}
function index()
{
$this->load->view('home_page');
}
function register()
{
//Validation Rules
$rules['username'] = "trim|required|min_length[5]|max_length[12]|xss_clean";
$rules['first_name'] = "trim|required|min_length[5]|max_length[12]|xss_clean";
$rules['last_name'] = "trim|required|min_length[5]|max_length[12]|xss_clean";
$rules['password'] = "trim|required|matches[passconf]|xss_clean";
$rules['passconf'] = "trim|required|min_length[5]|max_length[12]|xss_clean";
$rules['email'] = "trim|required|valid_email";
$this->validation->set_rules($rules);
//Sets the fields for use in the view
$fields['username'] = 'Username';
$fields['first_name'] = 'First Name';
$fields['last_name'] = 'Last Name';
$fields['password'] = 'Password';
$fields['passconf'] = 'Password Confirmation';
$fields['email'] = 'Email Address';
$this->validation->set_fields($fields);
//Checks to see if the validation has been succesful
if ($this->validation->run() == FALSE)
{
$this->load->view('register');
}
else
{
echo "Validation succesful. Do something.";
}
}
}
?>
Code:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html >
<head>
<title>BSL Learning Support</title>
<link rel="stylesheet" href="<?php echo base_url(); ?>css/layout2.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div class="wrapper">
<div id="logo">
<img src="<?php echo base_url(); ?>images/logo.gif">
</div>
<ul id="nav">
<li><a href="#">Home</a></li>
<li><a href="#">Section One</a></li>
<li><a href="#">Section Two</a></li>
<li><a href="#">Section Three</a></li>
<li><a href="#">Section Four</a></li>
<li><a href="#">Section Five</a></li>
<li><a href="http://www.cacdp.org.uk/">CACDP Website</a></li>
</ul>
</div>
<div id="top">
<div class="wrapper">
<div class="text_full_width">
<h2>Register for BSL 101 Resource</h2>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam a metus. Suspendisse fermentum dolor ut lacus. Suspendisse neque arcu, vehicula in, tincidunt ut, ornare vel, velit. Donec vel tortor. Proin turpis metus, viverra in, ullamcorper pulvinar, iaculis ut, purus. Suspendisse varius neque id pede. Aliquam erat volutpat. Nam ac nisl non purus varius tempor. Curabitur vehicula dictum turpis. Duis est nisl, tincidunt nec, adipiscing a, dictum eu, sapien. Cras ultrices bibendum nulla. Sed euismod lorem tincidunt metus. Ut tincidunt urna ut dui suscipit sagittis. Sed scelerisque metus non dui. Etiam vitae ipsum. Pellentesque placerat tincidunt urna. Cras purus diam, tristique eget, lobortis vel, facilisis ac, odio.</p>
</div>
</div>
</div>
<div class="wrapper">
<div class="content_middle">
<h2>Register</h2>
<?php echo $this->validation->error_string; ?>
<?php echo form_open("welcome/register");?>
<p><lebel>Username</label> <input type="text" name="username" value="<?php echo $this->validation->username;?>" size="50" /></p>
<p><lebel>First Name</label> <input type="text" name="first_name" value="<?php echo $this->validation->first_name;?>" size="50" /></p>
<p><lebel>Last Name</label> <input type="text" name="last_name" value="<?php echo $this->validation->last_name;?>" size="50" /></p>
<p><lebel>Password</label> <input type="text" name="password" value="<?php echo $this->validation->password;?>" size="50" /></p>
<p><lebel>Password Confirm</label> <input type="text" name="passconf" value="<?php echo $this->validation->passconf;?>" size="50" /></p>
<p><label>Email Address</label> <input type="text" name="email" value="<?php echo $this->validation->email;?>" size="50" /></p>
<div><input type="submit" value="Submit" /></div>
</form>
</div>
</div>
</body>
</html>