Welcome Guest, Not a member yet? Register   Sign In
Problem with form_error() -function
#1

[eluser]mjstenbe[/eluser]
Hi,
Im new to CI and am currently learning the system and its capabilities. I was reading through the documentation and tried to implement a simple form with validation. The basic functionality seems to be working ok, but I cant seem to get any output from form_error() function to display field spesific errors? The $this->validation->error_string does work fine, however, and prints out all the errors at once. Whats wrong here?

Below is my code for the view.

Code:
<h1>Entering user data</h1>

   &lt;?php echo $this->validation->error_string;?&gt;
                
    &lt;?php echo form_open('validator');?&gt;
    &lt;?php echo '<p>'.form_error('firstname').'</p>'; ?&gt;
    <p>First Name &lt;input type="text" name="firstname" value="&lt;?php echo set_value('firstname');?&gt;" size="50" /&gt;&lt;/p>

    <p>&lt;input type="submit" value="Send Data" /&gt;&lt;/p>
    &lt;/form&gt;
And here's the controller:

Code:
class Validator extends Controller {

    function Validator() {

    // load controller parent

        parent::Controller();

        // load 'url' helper

        $this->load->helper('url');

        // load 'form' helper

        $this->load->helper('form');
        
        // load 'validation' class

        $this->load->library('validation');

    }

    function index() {

    // set validation rules

        $rules['firstname']="required|min_length[6]|max_length[15]|trim|xss_clean";
        $rules['lastname']="required|min_length[6]|max_length[15]|trim|xss_clean";
        $rules['email']="required|valid_email|trim|xss_clean";

        $this->validation->set_rules($rules);

        // check if form has been submitted properly

        if ($this->validation->run()==FALSE) {

        // redisplay web form

            $this->load->view('form_view');

        }

        // display success web page

        else {

            $this->load->view('success_view');

        }

    }

}

Thanks for any help.


Messages In This Thread
Problem with form_error() -function - by El Forum - 02-19-2010, 03:31 AM
Problem with form_error() -function - by El Forum - 02-19-2010, 04:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB