Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can set your own type of validation functions. It is pretty well documented <a href="http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#callbacks" rel="nofollow">here</a>, but an excerpt would be:</p> <pre><code>&lt;?php class Form extends CI_Controller { public function index() { $this-&gt;load-&gt;helper(array('form', 'url')); $this-&gt;load-&gt;library('form_validation'); $this-&gt;form_validation-&gt;set_rules('username', 'Username', 'callback_username_check'); $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'required'); $this-&gt;form_validation-&gt;set_rules('passconf', 'Password Confirmation', 'required'); $this-&gt;form_validation-&gt;set_rules('email', 'Email', 'required|is_unique[users.email]'); if ($this-&gt;form_validation-&gt;run() == FALSE) { $this-&gt;load-&gt;view('myform'); } else { $this-&gt;load-&gt;view('formsuccess'); } } public function username_check($str) { if ($str == 'test') { $this-&gt;form_validation-&gt;set_message('username_check', 'The %s field can not be the word "test"'); return FALSE; } else { return TRUE; } } } ?&gt; </code></pre> <p><code>callback_username_check</code> is calling the <code>username_check</code> function in the controller</p> <p><strong>To answer your latest comment</strong></p> <pre><code>// $data is $_POST function my_form_validator($data) { $data = 'dont worry about this'; // you have access to $_POST here $field1 = $_POST['field1']; if($field1 OR $field2 OR $field3) { // your fields have value return TRUE; } else { // your fields dont have any value $this-&gt;form_validation-&gt;set_message('field1', 'At least one of the 3 fields should have a value'); 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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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