0

Probably there is something I am missing out. I looked around the web and SO for an answer for nothing fixed it for me. Here's my problem: I am loading form_validation library in the __construct method still PHP complains that validation_errors method is undefined. Also form helper is autoloaded.

...
...
function __construct()
{
    parent::__construct();
    $this->load->library('ion_auth');
    $this->load->library('form_validation');
    $this->load->helper('url');
....
....
function login()
{
    $this->data['title'] = "Login";
    .....
    .....
    //the user is not logging in so display the login page
        //set the flash data error message if there is one
        $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');

Error is thrown on the last line above. (This code is part of ion_auth module http://benedmunds.com/ion_auth/)

2
  • Did you run the validation already ? Commented Mar 31, 2014 at 19:30
  • No. the page errors out on first hit itself. Commented Mar 31, 2014 at 19:33

2 Answers 2

1

You may try this:

$this->data['message'] = ($this->form_validation->run() == False) ? validation_errors() : $this->session->flashdata('message');

Also make sure helper (form_helper.php) is loaded before you call the validation_errors() helper function because this function is available in this helper file. To load the helper file you may use:

$this->load->helper('form');
Sign up to request clarification or add additional context in comments.

6 Comments

Hmm.. but I have used this code before and is part of a standard library, thus it looks like a problem with the current configuration. Any hint on that part?
I'm not sure about ion_auth but if the error message says that, validation_errors() function is not defined then definitely the helper is not loaded and you may even load this from config/autoload.php using $autoload['helper'] = array('form'); to auto load it in every request.
Yes, its already added to autoload. Still the function is undefined. Next if I comment out the error line I get an error for form_open()
Out of my knowledge, why form_open error should occur ? The form_open is also a part of form helper and if the helper is already loaded then it doesn't make any sense for the error.
So did I (almost 5 years) and now migrated to Laravel, you should try this, you'll love it.
|
0

You should call run() method of form_validation class. Also you should define form variables.

$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
$this->form_validation->set_rules('email', 'Email', 'required');

if ($this->form_validation->run() == FALSE)
    $this->data['message'] = $this->session->flashdata('message');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.