From c644128fdd49a47d791240e0e38b54cd22412bc5 Mon Sep 17 00:00:00 2001
From: Derek Allard
=anchor('form', 'Try it again!'); ?>
+<p><?=anchor('form', 'Try it again!'); ?></p> - -In addition to the validation functions like the ones we used above, you can also prep your data in various ways. -For example, you can set up rules like this: +For example, you can set up rules like this:
$rules['username'] = "trim|required|min_length[5]|max_length[12]|xss_clean";
$rules['password'] = "trim|required|matches[passconf]|md5";
@@ -451,34 +454,36 @@ error message.
Now open your myform.php view file and update the value in each field so that it has an object corresponding to its name:
-
-
-My Form
-
-
+
+<html>
+<head>
+<title>My Form</title>
+</head>
+<body>
-=$this->validation->error_string; ?>
+<?=$this->validation->error_string; ?>
-=form_open('form'); ?>
+<?=form_open('form'); ?>
-Username
-
+<h5>Username</h5>
+<input type="text" name="username" value="<?=$this->validation->username;?>" size="50" />
-Password
-
+<h5>Password</h5>
+<input type="text" name="password" value="<?=$this->validation->password;?>" size="50" />
-Password Confirm
-
+<h5>Password Confirm</h5>
+<input type="text" name="passconf" value="<?=$this->validation->passconf;?>" size="50" />
-Email Address
-
+<h5>Email Address</h5>
+<input type="text" name="email" value="<?=$this->validation->email;?>" size="50" />
-
+<div><input type="submit" value="Submit" /></div>
-
+</form>
-
-
+</body>
+</html>
+
Now reload your page and submit the form so that it triggers an error. Your form fields should be populated
@@ -491,22 +496,22 @@ and the error messages will contain a more relevant field name.
If you prefer to show an error message next to each form field, rather than as a list, you can change your form so that it looks like this:
-
-Username
-=$this->validation->username_error; ?>
-
+<textarea class="textarea" style="width:100%" cols="50" rows="20">
+<h5>Username</h5>
+<?=$this->validation->username_error; ?>
+<input type="text" name="username" value="<?=$this->validation->username;?>" size="50" />
-Password
-=$this->validation->password_error; ?>
-
+<h5>Password</h5>
+<?=$this->validation->password_error; ?>
+<input type="text" name="password" value="<?=$this->validation->password;?>" size="50" />
-Password Confirm
-=$this->validation->passconf_error; ?>
-
+<h5>Password Confirm</h5>
+<?=$this->validation->passconf_error; ?>
+<input type="text" name="passconf" value="<?=$this->validation->passconf;?>" size="50" />
-Email Address
-=$this->validation->email_error; ?>
-
+<h5>Email Address</h5>
+<?=$this->validation->email_error; ?>
+<input type="text" name="email" value="<?=$this->validation->email;?>" size="50" /></textarea>
If there are no errors, nothing will be shown. If there is an error, the message will appear, wrapped in the delimiters you
have set (<p> tags by default).
@@ -589,16 +594,13 @@ For example, your "username" error will be available at:
$this->valida
Returns FALSE if the form element does not contain a valid email address.
-
+
valid_ip
No
Returns FALSE if the supplied IP is not valid.
-
-
-
Note: These rules can also be called as discreet functions. For example:
@@ -714,7 +716,7 @@ Previous Topic: User Agent Class
Top of Page ·
User Guide Home ·
Next Topic: XML-RPC Class
-
+
CodeIgniter · Copyright © 2007 · Ellislab, Inc.
--
cgit v1.2.3-24-g4f1b