Form Helper - set_value() - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Form Helper - set_value() (/showthread.php?tid=62815) |
Form Helper - set_value() - jLinux - 08-29-2015 I have a form setup using the CI Form Helper, mainly the set_value() feature. The same view file with the form is used for creating new "pages", as well as editing pages, ill use the page_title as an example input from my form. PHP Code: <input type="text" id="page_title" name="page_title" value="<?php echo set_value('page_title', @$settings->title); ?>" /> So initially, that works fine..
The question I have is, when you populate the values in the field, hit submit, and the page is successfully created, how can I have the form loaded, with the values then being empty? RE: Form Helper - set_value() - RobertSF - 08-29-2015 When someone checks the checkbox, and they get a new form to fill out, you want the fields all empty, not with the values that were entered in the previous instance of the form? If yes, I did this. It involved extending the form validation library by creating a file called MY_form_validation.php in my application/libraries folder, and inserting this code. PHP Code: <?php So to clear out the fields, use $this->form_validation->clear_field_data() RE: Form Helper - set_value() - jLinux - 08-29-2015 (08-29-2015, 04:03 PM)RobertSF Wrote: When someone checks the checkbox, and they get a new form to fill out, you want the fields all empty, not with the values that were entered in the previous instance of the form? Answer: Yes I was hoping there was a way to do it without extending the CI framework, (Trying to do as little of that as possible), but this way is definitely better than my way, thanks! RE: Form Helper - set_value() - jLinux - 08-30-2015 So, oddly enough, this doesnt work actually Edit: Maybe were using diff CI versions? But the code for set_value doesnt even look for _field_data, just looks right at $this->post form_helper.php: PHP Code: <?php RE: Form Helper - set_value() - jLinux - 08-30-2015 So I couldnt find a good way to unset $_POST without causing more errors, like in Input::_fetch_from_array(). Just gonna set a variable $empty_values, then.. PHP Code: <?php @$empty_values || print(set_value('menu_title', @$settings->menu_title)); ?> RE: Form Helper - set_value() - RobertSF - 08-30-2015 So sorry to have led you astray! The solution I posted works under CI 2.x, and I guess version 3 changed the code in the set_value function. Here's the code for version 2. PHP Code: /** Don't know how you feel about resorting to Javascript for this, but this function helps me when I want to prevent someone from returning to a previously filled and submitted form. They can return to it, but the form will be blank. It's extremely simple. Code: function formReset() { RE: Form Helper - set_value() - jLinux - 08-30-2015 (08-30-2015, 09:49 AM)RobertSF Wrote: So sorry to have led you astray! The solution I posted works under CI 2.x, and I guess version 3 changed the code in the set_value function. Here's the code for version 2. When you say "Here is the code for version 2", do you mean CI v2, or version 2 of your set_value? lol. And I love JS, but not sure id like to use JS for this one. My bandaid .. PHP Code: <?php @$empty_values || print(set_value('menu_title', @$settings->menu_title)); ?> .. works ok for now. On the top of CI form related stuff though... You can look at this other issue! lol RE: Form Helper - set_value() - RobertSF - 08-30-2015 Ha, ha, no, I meant here's the code as it is in CI v2. I'll look at your other post, though a first glance tells me it's a bit out of my league. |