Welcome Guest, Not a member yet? Register   Sign In
Problems with Form validation
#1

[eluser]fireproofsocks[/eluser]
I moved my form validation rules to a config file as outlined here:
http://ellislab.com/codeigniter/user-gui...ation.html

But as soon as I did that, the form never validates and no errors are shown. The forms were working before.

Anybody got ideas of what I can check? I'm using my own custom validation rules in libraries/MY_Form_validation.php

My Controller:
Code:
// Display the advanced search form
        if ($this->form_validation->run('contact_form') == FALSE)
        {
            $this->parser->parse('includes/contacts');
        }
        
        // Display the thank you message, send email
        else
        {
            $this->parser->parse('includes/thankyou');
        }

My config file (config/form_validation.php):
Code:
$config = array(
    'advanced_search'     => array(
        array(
            'field' => 'title_name',
            'label' => 'Title Name',
            'rules' => 'alpha_dash|xss_clean'
        ),
        array(
            'field' => 'categories[]',
            'label' => 'Title Categories',
            'rules' => 'is_mastercode[categories]'
        ),        
    ),
    /*-----------------------------------------------------*/
    'contact_form'         => array(
        array(
            'field' => 'first_name',
            'label' => 'First Name',
            'rules' => 'trim|required|alpha|min_length[2]|xss_clean'
        ),
        array(
            'field' => 'last_name',
            'label' => 'Last Name',
            'rules' => 'trim|required|alpha|min_length[2]|xss_clean'
        ),

    ),
);
#2

[eluser]InsiteFX[/eluser]
Hi everettg_99,

Not sure if this will help, but I think the problem is that your useinng a extended for_validation.

Try name your config file the same as your MY_Form_validation.php and see if it will load.

Enjoy
InsiteFX
#3

[eluser]fireproofsocks[/eluser]
AHA! The config file DOES have to be named form_validation.php... but looking through the source code, I could see that the configuration array is passed to the Form_validation constructor. So I just had to modify my constructor statement in libraries/MY_Form_validation.php script to match the parent constructor:

Code:
class MY_Form_validation extends CI_Form_validation {

    function MY_Form_validation($rules=array() )
    {
        parent::CI_Form_validation($rules);
    }

    function custom_stuff( $str )
    {
// ... etc...

It must be late... but this wasn't immediately obvious... I guess the lesson here is to look at how the parent is constructed before you extend it.
#4

[eluser]Aether[/eluser]
Thank you for this reply! I made a same mistake and fix it!




Theme © iAndrew 2016 - Forum software by © MyBB