CodeIgniter表單驗(yàn)證方法實(shí)例詳解
本文實(shí)例講述了CodeIgniter表單驗(yàn)證方法。分享給大家供大家參考,具體如下:
1.在D:\CodeIgniter\system\application\views目錄下寫(xiě)一個(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>
然后再寫(xiě)一個(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目錄下寫(xiě)一個(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訪(fǎng)問(wèn)一下
Ok,結(jié)果都出來(lái)了
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《codeigniter入門(mén)教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《php日期與時(shí)間用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門(mén)教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
相關(guān)文章
ThinkPHP3.2.3框架實(shí)現(xiàn)的空模塊、空控制器、空操作,跳轉(zhuǎn)到錯(cuò)誤404頁(yè)面圖文詳解
這篇文章主要介紹了ThinkPHP3.2.3框架實(shí)現(xiàn)的空模塊、空控制器、空操作,跳轉(zhuǎn)到錯(cuò)誤404頁(yè)面,結(jié)合圖文形式詳細(xì)分析了thinkPHP3.2.3框架空模塊、空控制器、空操作,跳轉(zhuǎn)到錯(cuò)誤404頁(yè)面具體操作步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-04-04php中使用$_REQUEST需要注意的一個(gè)問(wèn)題
本篇文章介紹了,php中使用$_REQUEST需要注意的一個(gè)問(wèn)題,需要的朋友參考下2013-05-05PHP提取字符串中的手機(jī)號(hào)正則表達(dá)式怎么寫(xiě)
PHP通過(guò)正則表達(dá)式提取字符串中的手機(jī)號(hào)并判斷運(yùn)營(yíng)商,簡(jiǎn)單快速方便,能提取多個(gè)手機(jī)號(hào)。下面通過(guò)本文實(shí)例代碼給大家詳細(xì)介紹,需要的的朋友參考下吧2017-07-07在Laravel5中正確設(shè)置文件權(quán)限的方法
這篇文章主要給大家介紹了關(guān)于如何在Laravel5中正確設(shè)置文件權(quán)限的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Laravel5具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05