這篇文章給大家分享的是有關(guān)CodeIgniter如何實現(xiàn)表單驗證的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
成都創(chuàng)新互聯(lián)專注于企業(yè)成都全網(wǎng)營銷、網(wǎng)站重做改版、青州網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、H5頁面制作、成都商城網(wǎng)站開發(fā)、集團公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)公司、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為青州等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。具體如下:
1.在D:\CodeIgniter\system\application\views目錄下寫一個視圖文件myform.php
<html> <head> <title>My Form</title> </head> <body> <?php echo $this->validation->error_string;?> <?php echo form_open('form/index');?> <h6>Username</h6> <input type="text" name="username" value="" size="50" /> <h6>Password</h6> <input type="text" name="password" value="" size="50" /> <h6>Password Confirm</h6> <input type="text" name="passconf" value="" size="50" /> <h6>Email Address</h6> <input type="text" name="email" value="" size="50" /> <div><input type="submit" value="Submit" /></div> </form> </body> </html>
然后再寫一個視圖文件formsuccess.php
<html> <head> <title>My Form</title> </head> <body> <h4>Your form was successfully submitted!</h4> <p><?=anchor('form', 'Try it again!'); ?></p> </body> </html>
2.在D:\CodeIgniter\system\application\controllers目錄下寫一個控制器文件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)于“CodeIgniter如何實現(xiàn)表單驗證”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
分享名稱:CodeIgniter如何實現(xiàn)表單驗證-創(chuàng)新互聯(lián)
網(wǎng)頁URL:http://www.rwnh.cn/article40/dosoeo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、建站公司、商城網(wǎng)站、ChatGPT、App設(shè)計、軟件開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)