Welcome Guest, Not a member yet? Register   Sign In
Help with passing form values via ajax (jquery) to codeigniter form validate.
#6

[eluser]dottedquad[/eluser]
[quote author="pickupman" date="1276159857"]You can create variables in your controllers construct function.
[/quote]

Controller code:
Code:
<?php
class Validate_livestock_form extends Controller
{
    var $validated_fields;
    
    function Validate_livestock_form(){
        parent::Controller();
        
        $this->$validated_fields = array();
    }
    
    function index()
    {
        //echo 'species: '.$species;
        
        $this->load->library('form_validation');
        
        $this->form_validation->set_rules('species', 'Species', 'callback_species_check');
        
        if ($this->form_validation->run() == FALSE)
        {
            echo json_encode($this->$validated_fields);
        }
        else
        {
            echo json_encode($this->$validated_fields);
        }
    }
    
    function species_check($str)
    {
        if ($str != '1')
        {
            
            $this->$validated_fields['species'] = "Please select a species!";
            return FALSE;
        }
        else
        {
            return TRUE;
        }
    }
    
}
?>

I'm receiving this error:
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: validated_fields

Filename: controllers/validate_livestock_form.php

Line Number: 9

Fatal error: Cannot access empty property in C:\wamp\www\lsms\system\application\controllers\validate_livestock_form.php on line 9

I have var $validated_fields; in the class so there should be an empty variable ready to be manipulated. the notice stated undefined variable... What does it mean by undefined and how do I define it? I'm also a bit confused with the Fatal error: Cannot access empty property message. Of course it's empty, by default there shouldn't be anything assigned to it. The point of the species_check function is to check validation if it's true assign some values to the $validated_fields array which has been stated. What should I do/change to fix this issue?

-Thanks,
Rich


Messages In This Thread
Help with passing form values via ajax (jquery) to codeigniter form validate. - by El Forum - 06-09-2010, 10:42 PM



Theme © iAndrew 2016 - Forum software by © MyBB