• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Setting a default value for a form with form validation library

Is there a way to set a default value when a form is first loaded with the Form Validation library?

Here it the function page in my controller, I load the validation library in my constructor.

function join()
    //echo "Got here";
        //echo "Two by two";
        $this->validation->set_error_delimiters('<div class="error_message">', '</div>');
        //$rules['username']    = "required";
        //$rules['password']    = "required";
        //$rules['passconf']    = "required";
        $rules['email']        = "trim|required|valid_email|xss_clean|callback_email_check";


        $fields['email']    = 'Email Address';
        if ($this->validation->email == "")
            $this->validation->email = "tester default";
        if ($this->validation->run() == FALSE)

and here is the relevant part of the view

echo form_open('welcome/join', $attributes);

&lt;input type="text" name="email" value="&lt;?php echo $this-&gt;validation->email;?&gt;" id="email" maxlength="75" size="50" style="width:65%"  />
&lt;?php echo $this->validation->email_error; ?&gt;

This seems to work correctly setting the default value to 'tester default', but since it wasn't mentioned in the user guide I wonder if there is an easier way to do it, or if this is a bad idea.

I found this page http://www.sellersrank.com/codeigniter/u...rm-values/ which seems to describe how to do add to the existing validation class, but I would strongly prefer not to go that route.

Yes, see set_value() in the [url="http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html"]form helper[/url].

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.