CodeIgniter Forums
form problem - unable to display error messages - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: form problem - unable to display error messages (/showthread.php?tid=2502)



form problem - unable to display error messages - El Forum - 08-09-2007

[eluser]webdude[/eluser]
For some reason when my validation == FALSE and I try to display <?=$this->validation->error_string; ?> on my page it does not diplay.


In my control I have the following:
Code:
<?php

    class Product_details  extends Controller {
    
        function Product_details()
        {
                parent::Controller();
                $this->load->helper(array('form', 'url'));
                $this->load->library('validation');                
        }
        
        function index()
        {
    
        }
        
        function productdetails()
        {            
                
        }
        
        function add()
        {
            $rules['qty'] = "numeric";
            
            $this->validation->set_rules($rules);
                
            if ($this->validation->run() == FALSE)
            {
                $this->load->view('product_details_view');
            }
            else
            {
                //$this->load->view('formsuccess');
                echo "success";
            }                
            
        }    
            
    }
?>
In my view I have the following:
Code:
<?=$this->validation->error_string; ?>

Thanks in advance


form problem - unable to display error messages - El Forum - 08-09-2007

[eluser]Phil Sturgeon[/eluser]
You problem most likly comes from not setting the $field variable, it needs both to validate properly.


form problem - unable to display error messages - El Forum - 08-09-2007

[eluser]webdude[/eluser]
thats not it.


form problem - unable to display error messages - El Forum - 08-09-2007

[eluser]Phil Sturgeon[/eluser]
Realised that after i said it, erm, im not sure what it is, the code is exactly the same as my own except for you have library in a constructor and I doubt thats it.

I would reccomend that you put rules for ALL elements in the form. If you have 5 fields and only two are required, you just use "required|whatever" for those and "trim" or something useful for the rest.