Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My suggestion is to tuck your validation rules into a separate file. CodeIgniter supports this by allowing you to save validation configurations in <code>config/form_validation.php</code>. Take a look at the <a href="http://codeigniter.com/user_guide/libraries/form_validation.html" rel="nofollow">Form Validation Documentation</a>, specifically the section labelled <strong>Saving Sets of Validation Rules to a Config File.</strong></p> <h2>Your controller's index:</h2> <pre><code>public function index() { $this-&gt;load-&gt;library('form_validation'); if($this-&gt;form_validation-&gt;run('submit_registration') == FALSE) { $this-&gt;load-&gt;view('registration'); } else{ $this-&gt;registration_model-&gt;add_user(); } } </code></pre> <h2>config/form_validation.php</h2> <pre><code>$config = array ( 'submit_registration' =&gt; array ( array( 'field' =&gt; 'email', 'label' =&gt; 'Email', 'rules' =&gt; 'trim|required|valid_email|email_available' ), array( 'field' =&gt; 'username', 'label' =&gt; 'Username', 'rules' =&gt; 'required|alpha_numeric|etc' ) ), 'some_other_submission' =&gt; array( array( 'field' =&gt; 'somefield', 'label' =&gt; 'SomeField', 'rules' =&gt; 'some|rules' ), array( 'field' =&gt; 'getit', 'label' =&gt; 'Get The Point?', 'rules' =&gt; 'trim' ) ) ); </code></pre> <h2>libraries/MY_Form_validation.php</h2> <pre><code>class MY_Form_validation extends CI_Form_validation { function __construct($config = array()){ parent::__construct($config); } function email_available($email){ $CI =&amp; get_instance(); //check your database with the $CI variable... if(email_exists) return TRUE; else return FALSE; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload