我有自己的字段验证问题。现在,表单中有5-6个字段。所以我正在检查我的控制器中的每一个,如果有错误,我希望再次加载视图并将错误数组传递给它。传递数组以查看codeigniter
我实现这个上面的功能:
<html>
<head>
<title>My Form</title>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
</head>
<body>
<?php
echo $fullname;
?>
<?
echo form_open('/membership/register');
?>
<h5>Username</h5>
<input type="text" name="username" value="" size="50" />
<h5>Password</h5>
<input type="text" name="password" value="" size="50" />
<h5>Password Confirm</h5>
<input type="text" name="cpassword" value="" size="50" />
<h5>Email Address</h5>
<input type="text" name="email" value="" size="50" />
<h5>Mobile</h5>
<input type="text" name="mobile" value="" size="15" />
<h5>Home</h5>
<input type="text" name="home" value="" size="15" />
<h5>Full Name</h5>
<input type="text" name="fullname" value="" size="100" />
<br><br>
<div><input type="submit" value="Submit" /></div>
</form>
</body>
</html>
和控制器的代码是:
if (preg_match('#[0-9]#',$fullname))
{
$errors['fullname'] = 'wrong name format!';
$this->load->view('register', $errors);
}
现在真正的问题我已经是,如果许多领域都是错误的。我想要传递$ errors数组来查看并访问它包含的所有值。所以我不必指定$全名或$手机来获得价值。如何才能做到这一点?以向用户显示一切缺失