Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeIgniter custom validate function not working
    primarykey
    data
    text
    <p>I am using CodeIgniter 2.3.1 and created a <code>form_validation.php</code> file in <code>config</code> and the content is as below.</p> <pre><code>&lt;?php $config = array( array( 'field' =&gt; 'firstname', 'label' =&gt; 'First Name', 'rules' =&gt; 'required' ), array( 'field' =&gt; 'lastname', 'label' =&gt; 'Last Name', 'rules' =&gt; 'required' ), array( 'field' =&gt; 'email', 'label' =&gt; 'Email', 'rules' =&gt; 'required|valid_email|callback_unique_email' ), array( 'field' =&gt; 'password', 'label' =&gt; 'Password', 'rules' =&gt; 'required|matches[confirm_password]' ), array( 'field' =&gt; 'confirm_password', 'label' =&gt; 'Confirm Password', 'rules' =&gt; 'required' ) ); function unique_email($email) { if($email == 'm@gmail.com') { $this-&gt;form_validation-&gt;set_message('unique_email', 'Hello World !'); return false; } } ?&gt; </code></pre> <p>And checking the <code>form_validation</code> in <code>register</code> function of <code>user</code> controller. The code is below.</p> <pre><code>public function register() { $this-&gt;load-&gt;helper('form'); $data['message'] = ''; if($this-&gt;input-&gt;post('submit')) { $this-&gt;load-&gt;library('form_validation'); if($this-&gt;form_validation-&gt;run() == FALSE) { $data['message'] = 'User could not be saved.'; } else { $user_data['firstname'] = $this-&gt;input-&gt;post('firstname'); $user_data['lastname'] = $this-&gt;input-&gt;post('lastname'); $user_data['email'] = $this-&gt;input-&gt;post('email'); $user_data['password'] = md5($this-&gt;input-&gt;post('password')); if($this-&gt;user_model-&gt;insert($user_data)) { if($this-&gt;user_model-&gt;login($user_data)) { $this-&gt;session-&gt;set_flashdata('message', 'User saved successfully.'); redirect('/user', 'refresh'); } } } } $this-&gt;load-&gt;view('user/register', $data); } </code></pre> <p>But I am not getting validation message for the custom method. Please suggest me how to do it?. The work is more appreciated.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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