Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8715927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:57:41+00:00 2026-06-13T05:57:41+00:00

Trying to set-up a call back function, but it’s not working for some reason.

  • 0

Trying to set-up a call back function, but it’s not working for some reason. Not sure what I’m doing wrong here.

Look for the registration() and _email_check($str) functions in the controller below.

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Register extends CI_Controller {

public function __construct() 
{
    parent::__construct();
    $this -> load -> model('user_model');
}

public function index() 
{
    if (($this -> session -> userdata('user_name') != "")) {
        redirect('dashboard');
    } 
    else
    {
        $data['title'] = 'Register';
        $this -> load -> view('shared/header_view', $data);
        $this -> load -> view("registration.php", $data);
        $this -> load -> view('shared/footer_view', $data);
    }
}

public function login() 
{
    $email = $this -> input -> post('email');
    $password = $this -> input -> post('pass');

    $result = $this -> user_model -> login($email, $password);
    if ($result)
        redirect('dashboard');
    else
        $this -> index();
}

public function registration() 
{
    $this -> load -> library('form_validation');
    // field name, error message, validation rules
    $this -> form_validation -> set_rules('user_name', 'User Name', 'trim|required|min_length[4]|xss_clean');
    $this -> form_validation -> set_rules('email_address', 'Your Email', 'trim|required|valid_email', 'callback__email_check');
    $this -> form_validation -> set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
    $this -> form_validation -> set_rules('con_password', 'Password Confirmation', 'trim|required|matches[password]');

    if ($this -> form_validation -> run() == FALSE) 
    {
        $this -> index();
    } 
    else 
    {
        $this -> user_model -> add_user();

        $email = $this -> input -> post('email');
        $password = $this -> input -> post('pass');            

        $result = $this -> user_model -> login($email, $password);
        if ($result)
        {
            redirect('dashboard');  
        }          
    }        
}

// Checks that Email Address is not in use
public function _email_check($str)
{
    // return true if the address is indeed a new address
    $this -> db -> where('email', $str);
    $found = $this -> db -> get('user') -> num_results(); // this returns the number of rows having the same address.

    if ($found!=0)
    {
        $this -> form_validation -> set_message('email_check', 'Email Address is already in use');
        return false;  // more than 0 rows found. the callback fails.
    }
    else
    {
        return true;   // 0 rows found. callback is ok.
    }
}

public function logout() 
{
    $newdata = array('user_id' => '', 'user_name' => '', 'user_email' => '', 'logged_in' => FALSE, );
    $this -> session -> unset_userdata($newdata);
    $this -> session -> sess_destroy();
    redirect(base_url());
}
}

Here’s the MODEL in case you need it:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class User_model extends CI_Model {

public function __construct() {
    parent::__construct();
}

function login($email, $password) 
{
    $this -> db -> where("email", $email);
    $this -> db -> where("password", $password);

    $query = $this -> db -> get("user");
    if ($query -> num_rows() > 0) 
    {
        foreach ($query->result() as $rows) 
        {
            //add all data to session
            $newdata = array(
                'user_id' => $rows -> id,
                'user_name' => $rows -> username,
                'user_email' => $rows -> email,
                'logged_in' => TRUE,
            );
        }
        $this -> session -> set_userdata($newdata);
        return true;
    }
    return false;
}

public function add_user() 
{
    $data = array(
        'username' => $this -> input -> post('user_name'),
        'email' => $this -> input -> post('email_address'),
        'password' => $this -> input -> post('password'),
    );
    $this -> db -> insert('user', $data);
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:57:42+00:00Added an answer on June 13, 2026 at 5:57 am

    Ugh… just told you to troubleshoot and the problem is you’re calling the callback wrong.

        $this -> form_validation -> set_rules('email_address', 'Your Email', 'trim|required|valid_email|callback__email_check')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a custom session persister in PHP. But for some reason
I'm trying to add a method to the Event prototype. In order to call/set
I'm trying to call a actor to do something time consuming. The caller set
I'm currently trying to make a set of conversion functions which, through one call,
Does anybody know how to debug call to undefined function init_set , when trying
Trying to set a flag in the post to allow processing or not. The
I'm trying to redraw a GtkDrawingArea using the gtk_widget_queue_draw function, but the widget is
I am trying to get a jQuery.ajax to call back to the calling instance
Okay, so I'm trying to set a variable via a javascript method call. However
I'm trying to debug JavaScript code using Visual Studio 2010, but I can't set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.