CodeIgniter Forums
Validation Class [SOLVED] - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Validation Class [SOLVED] (/showthread.php?tid=10604)



Validation Class [SOLVED] - El Forum - 08-06-2008

[eluser]Matthew Lanham[/eluser]
Hey guys,

I wanted some advice re the validation class...

We have a CRUD setup, and it works great for the create, but update seems to be a bit of an issue, i want to use the same view for the update when its first viewed and after the post, in the create view i have:

<?php echo $this->validation->price_rrp;?> in the value element of the input fields

but if i do this in the update section, how can i get the initial data in those elements, i need some way of setting the data initially

Do i make sense????


Validation Class [SOLVED] - El Forum - 08-06-2008

[eluser]Matthew Lanham[/eluser]
Ok so i figured this one out, i done some digging in the validation class and noticed it used $_POST to find items and set data etc.

So basically in my controller i have:

Code:
//Set validation data from the Model
$this->validation->set_rules($this->product->rules);
$this->validation->set_fields($this->product->fields);
$this->validation->set_error_delimiters('<li>', '</li>');
        
if($this->input->post('save')){
    //The form has been submitted
    $this->validation->run();
    
}else{
    //The form has NOT been submitted
    //Fill $_POST with data from the database
    $_POST = $this->product->find('array');
    $this->validation->run();
}

In my model Product i have the array of rules, fields and i have created the find function and it has a switch for the data returned, array will return an array blank will return an object...

Hope this helps someone