Form Data reset before submit |
Hi,
There are 2 things here: - your code looks like to belong to Codeigntier 3 and not version 4 - in the view you need to prepare the form to allow re-population of the value. Read the following: https://codeigniter.com/user_guide/libra...g-the-form What i started to use with PHP 7.* is the null coalesce operator to help me with this. Consider the below: In the model or the controller i have the fields set up like this: PHP Code: $fields['flag_promix'] = [ In the view i display the form as below: PHP Code: <?= form_checkbox($fields['flag_promix']['name'], $fields['flag_promix']['value'], $fields['flag_promix']['checked'],$fields['flag_promix']['attributes']) ?> The magic is this piece of code in the controller (or model in my case): PHP Code: 'checked' => $this->input->post('flag_promix') ?? $existingValues['flag_promix'] ?? NULL, If the form has already been submitted then the value will be set by $this->input->post() If the form has not been submitted yet, then this field will get the value from a database which i store in $existingValues array If neither the post data nor the data base data has this value, then it is set to NULL but you can define a default value here as well. |
Messages In This Thread |
Form Data reset before submit - by sanjaya - 09-05-2018, 04:19 AM
RE: Form Data reset before submit - by sanjaya - 09-05-2018, 04:24 AM
RE: Form Data reset before submit - by qury - 09-05-2018, 04:39 AM
RE: Form Data reset before submit - by Nome - 09-05-2018, 05:00 AM
|