Welcome Guest, Not a member yet? Register   Sign In
Clearing form fields?
#1

[eluser]mrh[/eluser]
Hello All,

I have a small form that takes in some transaction data: date, amount, code, description. I have form_validation loaded, form helper loaded. In the "submit" method of my class I run the form validation like in the example. If it fails I simply load the form again. I am using set_value( 'field', $default ) where I populate an array of $default values before loading the form. So on a reload after failed validation I am assuming set_value uses the first parm to get the data from the input->post data. This all seems to work and errors show up etc.

Now... when everything passes validation. I save the input data to the database and I want to simply reload the form so the operator can keep entering data. This "sort of" works. I call the exact same method:

Code:
self::projtran();

as if they clicked on a link to get there. I have link to the page which calls: class/projtran

The issue is that when I click on the link the form fields are nice and clear as I want them to be. I enter a new transaction and submit it. Assuming it passes validation it gets written to the database and that works. But after saving the data to the database I'm calling self::projtran() which I thought would be roughly equivalent to clicking on the link to go to that page. But it leaves the data in the form fields.

So ok... I tried to get tricky. I tried clearing $_POST and making sure my $default values were inited to blanks. Still the data seems to populate. It is almost as if the browser is caching the field data.

Any ideas? I can certainly post more code but there is quite a bit of it. I guess before I post code I'm wondering about if you submit form a form and then immediately reload that form is there a common way to ensure the fields are set to empty (or desired default values) instead of the last entered data?

I'm not sure if this is an issue with set_value() or if it is the browser caching something. Either way I'm hoping someone knows away to flush the last entered data and sort of start over fresh. Again if I put an intermediate form in place that says something like transaction accepted and it has a link to call class/projtran then it works great. It is like the act of clicking on the link to go to that class/view is working but simply calling the function in code is not giving the same result.

Any help would be appreciated.
#2

[eluser]Aken[/eluser]
Just redirect() back to the form page.
#3

[eluser]mrh[/eluser]
Thank you sir! One day I'll give back all I'm getting from this forum!




Theme © iAndrew 2016 - Forum software by © MyBB