Welcome Guest, Not a member yet? Register   Sign In
form_validation error
#1

I'm creating a library to add new users.

Code:
class Register
   {
       private $CI;
       public function add_new_user()
       {
           $CI =& get_instance();
           $CI->form_validation->set_rules('email', 'Email', 'required|callback_is_email_exist');
           if ($CI->form_validation->run() == TRUE)
           {
               $email = $_POST['email'];
               $insert_data = array('email' => $email);
               $CI->new_data->add_user($insert_data);
           }
       }
       private function is_email_exist($email)
       {
           $CI =& get_instance();
           $email_result = '';
           $query = $CI->check->find_email($email);
           foreach ($query->result_array() as $row)
           {
               $email_result = $row['email'];
           }
           if ($email_result == $email)
           {
               $CI->form_validation->set_message('is_email_exist', 'Such email already exist!');
               return FALSE;
           }
           else
           {
               return TRUE;
           }
       }
   }
I add form_validation and models check, new_data to the autoload. When I submit a form instead of an error (if it should be there) I get Unable to access an error message corresponding to your field name Username.(is_username_exist). What should i do to fix this?
Reply
#2

This is a template class for using the CodeIgniter Super Object.

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

/**
 * ---------------------------------------------------------------
 * Editor   : PhpStorm
 * Date     : 8/25/2017
 * Time     : 7:13 AM
 * Authors  : Raymond L King Sr.
 * ---------------------------------------------------------------
 *
 * Class        Register
 *
 * @project     citest
 * @author      Raymond L King Sr.
 * @link        http://www.procoversfx.com
 * @copyright   Copyright (c) 2009 - 2017 Custom Software Designers, LLC.
 * @license     http://www.procoversfx.com/license
 * ---------------------------------------------------------------
 */


class Register
{
    
/**
     * Class variables - public, private, protected and static.
     * -------------------------------------------------------------------
     */

    /**
     * @var  CI_Controller
     * CodeIgniter's Super Object - this is the correct way to use it
     * Access using $this->CI->method
     */
    
protected $CI;

    
/**
     * __construct ()
     * -------------------------------------------------------------------
     *
     * Class    Constructor
     *
     * NOTE:    Not needed if not intializing class or variables.
     */
    
public function __construct()
    {
        
$this->CI =& get_instance(); 
    }

    
  // End of Register Class.


/**
 * ---------------------------------------------------------------
 * Filename: Register.php
 * Location: ./application/libraries/Register.php
 * ---------------------------------------------------------------
 */ 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB