Welcome Guest, Not a member yet? Register   Sign In
How do I preload a form?
#11

[eluser]Sondlen[/eluser]
The way the validation class is written seems like it's not supposed to be used for data preloading, but it works well, cuts down on the code needed and is faster to write so I like these hacks.
#12

[eluser]Natebot[/eluser]
Here's trifling edit to the set_select modification made above.

The value of the 'selected' attribute of the Option tag is "selected" (why, I have no idea when 'true' makes as much if not more sense.)

reference


Code:
function set_select($field = '', $value = ''){
  if ($field == '' OR $value == ''){
    return '';
  }
  $compareVal = isset($_POST[$field]) ? $_POST[$field] : $this->$field;
  if($compareVal == $value){
    return ' selected="selected"';
  }
}

Thanks for the extention, this makes coding my pre-populating dropdowns even faster!

er, also the value of the checked attribute is 'checked' for radio button and check box input fields.
Code:
return ' checked="checked"';

Reference
#13

[eluser]Jason Tan Boon Teck[/eluser]
[quote author="wiredesignz" date="1201411812"]... from the User Guide:

Code:
//in your view (untested)
<input type="checkbox" name="mycheck" value="1" <?= $this->validation->set_checkbox('mycheck', '1'); ?> />

//form continues...

to pre-load values into the validation object(after set_fields()):

Code:
//in your controller
$this->validation->mycheck = 1;
[/quote]

I do not see set_fields in the Form Validation class of v1.7.2. What is its replacement? What is the new version's way of prepopulating the variables?
#14

[eluser]mattpointblank[/eluser]
I have a way simpler method, which I've posted before.

Controller:
Code:
$this->load->model('Some_model');
$data['info'] = $this->Some_mode->getData();
$this->load->view('form', $data);

Form:
Code:
<input type="text" name="email" value="<?php echo set_value('email', $info['email_address']); ?>" />

Note that this will give a warning if $info doesn't exist.




Theme © iAndrew 2016 - Forum software by © MyBB