CodeIgniter表單驗(yàn)證方法實(shí)例詳解
本文實(shí)例講述了CodeIgniter表單驗(yàn)證方法。分享給大家供大家參考,具體如下:
1.在D:\CodeIgniter\system\application\views目錄下寫一個(gè)視圖文件myform.php
<html>
<head>
<title>My Form</title>
</head>
<body>
<?php echo $this->validation->error_string;?>
<?php echo form_open('form/index');?>
<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="passconf" value="" size="50" />
<h5>Email Address</h5>
<input type="text" name="email" value="" size="50" />
<div><input type="submit" value="Submit" /></div>
</form>
</body>
</html>
然后再寫一個(gè)視圖文件formsuccess.php
<html>
<head>
<title>My Form</title>
</head>
<body>
<h3>Your form was successfully submitted!</h3>
<p><?=anchor('form', 'Try it again!'); ?></p>
</body>
</html>
2.在D:\CodeIgniter\system\application\controllers目錄下寫一個(gè)控制器文件form.php
<?php
class Form extends Controller{
function index(){
$this->load->helper(array('form','url'));
$this->load->library('validation');
$rules['username'] = "required";
$rules['password'] = "required";
$rules['passconf'] = "required";
$rules['email'] = "required";
$this->validation->set_rules($rules);
// $this->validation->set_error_delimiters('<div class="error">','</div>');
$fields['username'] = 'Username';
$fields['password'] = 'Password';
$fields['passconf'] = 'Password Confirmation';
$fields['email'] = 'Email Address';
$this->validation->set_fields($fields);
if ($this->validation->run()==false) {
$this->load->view('MyView/myform');
}else {
$this->load->view('MyView/formsuccess.php');
}
}
}
?>
3.http://localhost:8888/index.php/form/index訪問一下
Ok,結(jié)果都出來了
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《php日期與時(shí)間用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
相關(guān)文章
Yii框架結(jié)合sphinx,Ajax實(shí)現(xiàn)搜索分頁功能示例
這篇文章主要介紹了Yii框架結(jié)合sphinx,Ajax實(shí)現(xiàn)搜索分頁功能,結(jié)合實(shí)例形式分析了Yii框架中使用sphinx與Ajax實(shí)現(xiàn)搜索結(jié)果的分頁展示效果,需要的朋友可以參考下2016-10-10
遍歷echsop的region表形成緩存的程序?qū)嵗a
下面小編就為大家?guī)硪黄闅vechsop的region表形成緩存的程序?qū)嵗a。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-11-11
thinkphp在php7環(huán)境下提示Cannot use ‘String’ as class name as it is
這篇文章主要介紹了thinkphp在php7環(huán)境下提示Cannot use ‘String’ as class name as it is reserved的解決方法,涉及thinkPHP針對(duì)php7關(guān)鍵字判定的相關(guān)底層代碼修改技巧,需要的朋友可以參考下2016-09-09
PHP flush()與ob_flush()的區(qū)別詳解
本篇文章是對(duì)PHP中的flush函數(shù)與ob_flush函數(shù)的區(qū)別進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
php版微信公眾平臺(tái)開發(fā)之驗(yàn)證步驟實(shí)例詳解
這篇文章主要介紹了php版微信公眾平臺(tái)開發(fā)之驗(yàn)證步驟,結(jié)合實(shí)例形式詳細(xì)分析了php微信公眾平臺(tái)驗(yàn)證的操作步驟與相關(guān)參數(shù)含義,需要的朋友可以參考下2016-09-09

