Welcome Guest, Not a member yet? Register   Sign In
default value in edit view
#1

[eluser]huzzi[/eluser]
I can't get this to work.. can't set the default value from within controller. I know how to get this working with the older version of CI. What am i doing wrong? please help.

view:
Code:
<input name="a" type="text" value="<?php echo set_value('a');?>" />

Controller:
Code:
function update(){
       $this->load->library('form_validation');
       $this->form_validation->set_rules('a', 'a', 'required');
       $this->form_validation->set_value('a','qwerty');

         if ($this->form_validation->run() == FALSE)
        {
          $this->render('member','member/update_profile');
        }
        else
        {
           // code to update
        }
}

Any help would be appriciated.

Many thanks.
#2

[eluser]Dam1an[/eluser]
Hmm, there doesn't appear to be anything in the user guide on
Code:
$this->form_validation->set_value();

Do you NEED to set it in the controller, cause you can set the default value in the view as a second paramter
#3

[eluser]huzzi[/eluser]
Thanks Dam1an,

How do you populate form data from database?

[quote author="Dam1an" date="1242406840"]Hmm, there doesn't appear to be anything in the user guide on
Code:
$this->form_validation->set_value();

Do you NEED to set it in the controller, cause you can set the default value in the view as a second paramter[/quote]
#4

[eluser]Dam1an[/eluser]
I've not actually done any edit forms using the new validation library lol
but an easy work around would be to pass the variables into the view and then use set_value('a', $a);
#5

[eluser]jdfwarrior[/eluser]
What does
Code:
value="<?php echo set_value('a');?>"
actually output in your html? Unless set_value is returning a value, that shouldn't be setting the value.

To update values of fields from a database,.. you would need javascript to do it without a page refresh. If you submitting the form back to itself, php will work

Sorry if this makes no sense. Its early, and i had a long night Smile




Theme © iAndrew 2016 - Forum software by © MyBB