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 7845787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:21:41+00:00 2026-06-02T17:21:41+00:00

I’m new to working with Codeigniter and need to set a form validation rule

  • 0

I’m new to working with Codeigniter and need to set a form validation rule and custom validation message for checking if the email address exists in the database that is submitted in a forgot password form. If the email address exists it sends an email, if it doesn’t it should reload the form, set the field value to what the user entered and provide an error that the email address doesn’t exist.

I’ve got the following in the controller…

public function forgot_password()
{
    $this->form_validation->set_rules('email_address','Email Address','trim|required|valid_email');

    if($this->form_validation->run() == FALSE)
    {
        $this->forgot_password_form();
    }
    else
    {
        $this->load->model('membership_model');
        if($query = $this->membership_model->val_forgot_password())
        {
            $data['main_content'] = 'forgot_password_sent';
            $this->load->view('includes/template', $data);
        }
        else
        {
            $this->form_validation->set_message('email_address','The email address you provided does not exist.');
            $this->forgot_password_form();
        }
    }
}

and in the model…

public function val_forgot_password()
{
    $this->db->where('email_address', $this->input->post('email_address'));
    $query = $this->db->get($this->members);

    if($query->num_rows == 1)
    {
        return true;
    }
    else
    {
        return false;
    }
}

and the form is…

<?php

echo form_open('login/forgot_password');
echo "Email Address: " . form_input('email_address', set_value('email_address', ''));
echo br(2);
echo form_submit('submit','Send Email');
echo form_close();
echo br(1);

echo validation_errors('<p>Error: ');

?>

When the form is submitted with a valid email address it correctly goes to the success page but if the email address doesn’t exist, it appears to reload the form but does not give an error.

Help pls! 😀

  • 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-02T17:21:42+00:00Added an answer on June 2, 2026 at 5:21 pm

    You should use a callback to check the email exists. So your controller would be something like…

    public function forgot_password()
    {
        $this->form_validation->set_rules('email_address','Email Address','trim|required|valid_email|callback__check_email_exists');
    
        if($this->form_validation->run() == FALSE)
        {
           // VALIDATION ERRORS, SHOW VIEWS
        }
        else
        {
          // ALL IS GOOD, UPDATE EMAIL, AND REDIRECT TO CURRENT URL
        }
    }
    

    And your callback (still in your controller) would be something like…

    public function _check_email_exists($email)
    {
      // LOAD AND USE YOUR MODEL TO CHECK EMAIL EXISTS HERE
      if ( ! $email_exists )
      {
        $this->form_validation->set_message('email_address', 'That email address don\'t exist, sucka!');
        return FALSE;
      }
      else
      {
        return TRUE;
      }
    }
    

    All this is spelled out in the excellent CI docs here, and I would recommend sticking to the CI conventions if you are new to it.

    http://codeigniter.com/user_guide/libraries/form_validation.html

    EDIT: There is also another problem i was facing while doing this in codeigniter3. You have to named the message field name to the callback. So instead of $this->form_validation->set_message('email_address', 'That email address don\'t exist, sucka!');

    This should be

    $this->form_validation->set_message('_check_email_exists', 'That email address don\'t exist, sucka!');

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to

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.