您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關(guān)CodeIgniter如何實現(xiàn)表單驗證的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
具體如下:
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)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。