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

  • Home
  • SEARCH
  • 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 4006536
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:31:36+00:00 2026-05-20T08:31:36+00:00

I do not understand why codeigniter form validator is always returning true. For a

  • 0

I do not understand why codeigniter form validator is always returning true. For a test, I am checking if the alias element value equals test. I entered test into the alias element and the jquery code executes the ajax. I checked the post value in firebug’s post tab and it says: alias=test However, codeigniter is also returning true. Why is it returning true when it should return false? Any help is greatly appreciated. -Thanks
codeignitor code:

<?php
class Validate_livestock extends Controller 
{
    //create a variable to be used for an array to pass back to the livestock form if there are errors.
    var $validate_field;

    function Validate_livestock()
    {
        parent::Controller();

        //echo 'species11: '.$fs;

        //turn the validation_field variable into an array
        $this->validate_field = $this->uri->uri_to_assoc(3);

    }

    function validate_form()
    {

        //load the form validation library
        $this->load->library('form_validation');

        //set form validation rules
        switch ($this->validate_field['field']){
        case "alias":
            $this->form_validation->set_rules('alias', 'Alias', 'callback_alias_check', 'trim|xss_clean');
            //echo 'input: ' . $this->input->post('alias');
        break;      
        }

        //see if the form validates

        if ($this->form_validation->run() == FALSE)
        {
            //print_r($this->validate_field['field']);
            $this->load->view('false');
            //echo $this->form_validation->run();
            //echo "Validator Successfully ran.";
        }
        else
        { 
            //print_r($this->validate_field['field']);
            $this->load->view('true');
            //echo $this->form_validation->run();
            //echo "Validator Unsuccessfully ran.";
        }

        function alias_check($str)
        {
            if ($str == 'test')
            {
                return FALSE;
            }
            else
            {
                return TRUE;
            }
        }
    }
    }
}
?>

jquery code:
$(document).ready(function() {
function validateElement(formId, element, errorContainer)
{

    $.ajax({
        type: 'POST',
        cache: false,
        url: "validate_livestock/" + "validate_form/field/" + element,
        data: element+"="+$('#'+element).val(),
        context: document.body,
        dataType: 'html',
        success: function(){
            alert(document.body)
        }
    });
}

$('#alias').change(function(){
    validateElement('#add_livestock', 'alias', '#alias_error_1')
}); 

});

  • 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-05-20T08:31:36+00:00Added an answer on May 20, 2026 at 8:31 am

    You seem to have the function, alias check inside the validate_form method

        function validate_form()
        {
    
            //load the form validation library
            $this->load->library('form_validation');
    
            //set form validation rules
            switch ($this->validate_field['field']){
            case "alias":
                $this->form_validation->set_rules('alias', 'Alias', 'callback_alias_check', 'trim|xss_clean');
                //echo 'input: ' . $this->input->post('alias');
            break;      
            }
    
            //see if the form validates
    
            if ($this->form_validation->run() == FALSE)
            {
                //print_r($this->validate_field['field']);
                $this->load->view('false');
                //echo $this->form_validation->run();
                //echo "Validator Successfully ran.";
            }
            else
            { 
                //print_r($this->validate_field['field']);
                $this->load->view('true');
                //echo $this->form_validation->run();
                //echo "Validator Unsuccessfully ran.";
            }
    
            function alias_check($str)
            {
                if ($str == 'test')
                {
                    return FALSE;
                }
                else
                {
                    return TRUE;
                }
            }
        }
    }
    

    You should have it outside that method:

    function validate_form() {}
    function alias_check(){}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There was an interesting question in a practice test that I did not understand
There is one thing that I do not understand... Imagine you have a text
I have encountered a rather odd error that I do not understand. I created
I read the SDK document, but can not understand some details, need some help.
There is a difference in the description on MSDN, however, I do not understand
I do not quite understand the difference between a C# reference and a pointer.
How universally is the C99 standard supported in today's compilers? I understand that not
I understand the reason behind not auto refreshing your .dbml (Linq2Sql), .edmx (Linq2Entities) or
I understand the reflection API (in c#) but I am not sure in what
I'm not completely sure I understand the workflow way of doing things, but if

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.