《PHP應用:CodeIgniter表單驗證方法實例詳解》要點:
本文介紹了PHP應用:CodeIgniter表單驗證方法實例詳解,希望對您有用。如果有疑問,可以聯系我們。
PHP學習本文實例講述了CodeIgniter表單驗證辦法.分享給大家供大家參考,具體如下:
PHP學習1.在D:\CodeIgniter\system\application\views目錄下寫一個視圖文件myform.php
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>
PHP學習然后再寫一個視圖文件formsuccess.php
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>
PHP學習2.在D:\CodeIgniter\system\application\controllers目錄下寫一個控制器文件form.php
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');
}
}
}
?>
PHP學習3.http://localhost:8888/index.php/form/index拜訪一下
PHP學習Ok,結果都出來了
PHP學習更多關于PHP相關內容感興趣的讀者可查看本站專題:《codeigniter入門教程》、《CI(CodeIgniter)框架進階教程》、《php日期與時間用法總結》、《php面向對象程序設計入門教程》、《php字符串(string)用法總結》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》
PHP學習希望本文所述對大家PHP程序設計有所贊助.
維易PHP培訓學院每天發布《PHP應用:CodeIgniter表單驗證方法實例詳解》等實戰技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養人才。
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/7482.html