form fields are being cleared when refrshing the web page - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: form fields are being cleared when refrshing the web page (/showthread.php?tid=16435) Pages:
1
2
|
form fields are being cleared when refrshing the web page - El Forum - 03-06-2009 [eluser]nir[/eluser] Hello All, In most cases the problems with form fields is that they are getting cached and not being cleared after successful submission in my case it's the opposite. when I hit the refresh button on the browser the form fields are getting cleared, also, If the form validation fails and you go back/redirected back to the form, again the form fields are getting cleared. -- I think that it somehow has to do with sessions but i can't figure out what is the problem. thanks in advanced. ~ nir ======================== CONTROLLER ===================================== Code: <?php ======================== VIEW =========================================== Code: <?php $this->load->view('header'); ?> form fields are being cleared when refrshing the web page - El Forum - 03-06-2009 [eluser]jdfwarrior[/eluser] Why do you echo all that HTML in your view? form fields are being cleared when refrshing the web page - El Forum - 03-06-2009 [eluser]nir[/eluser] what's the alternative??? i am just starting my way in php.... codeigniter... BTW this is how its being done in the book "Professional CodeIgniter" thanks form fields are being cleared when refrshing the web page - El Forum - 03-06-2009 [eluser]jdfwarrior[/eluser] Just use regular HTML and open the php where needed.. Code: <div id="wrapper"> That would use the php only where it was needed, in that one spot form fields are being cleared when refrshing the web page - El Forum - 03-06-2009 [eluser]nir[/eluser] thank you, it does look more "clean". any advice on the form fields no-caching after validation ??? thanks, nir form fields are being cleared when refrshing the web page - El Forum - 03-06-2009 [eluser]TheFuzzy0ne[/eluser] You need to set the value of the form fields using "set_value()". If you can post your controller, I can probably give you an example. form fields are being cleared when refrshing the web page - El Forum - 03-06-2009 [eluser]nir[/eluser] i've attached the controller code and the view code at the top of this posting. thank you, nir form fields are being cleared when refrshing the web page - El Forum - 03-06-2009 [eluser]TheFuzzy0ne[/eluser] Some general advice. CodeIgniter has a [url="http://ellislab.com/codeigniter/user-guide/libraries/sessions.html"]session library[/url] for you to use. It can make things a lot easier, I recommend you look into it. As you're using the session library anyway, it makes sense to use it to it's full potential. CodeIgniter also has [url="http://ellislab.com/codeigniter/user-guide/libraries/input.html"]a cleaner way to access post variables[/url], so you don't have to keep checking if they are set or not (they return FALSE when they don't exist). For repopulating the form, use set_value(). I see you're setting the form data in your view which I didn't notice, so here's an example of how to use it: Code: $data = array('name'=>'email','id'=>'email','size'=>35, 'value' => set_value('email')); EDIT: Another thing to note is that you do not need to call session_start(). The session library does all that for you. form fields are being cleared when refrshing the web page - El Forum - 03-06-2009 [eluser]nir[/eluser] thanks for the quick response. yes, i am auto loading the helpers and libraries in the config file. still, i add your code change and i am having the same problem the the form fields are being cleared when i just refresh the web page or the validation fails, instead of keeping the values in the fields till a successful submission. thanks again, nir form fields are being cleared when refrshing the web page - El Forum - 03-06-2009 [eluser]jdfwarrior[/eluser] Are you referring to like... you type a value in, and when you refresh it comes back? Like, for a name field, I type in my name and hit refresh, and it keeps that value after the refresh? |