 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
SanderK
Joined: 01 Jul 2008 Posts: 13
|
Posted: Tue Jul 15, 2008 5:57 am Post subject: Reset Form |
|
|
Hi Guys
I created a form with a textfield and a submit button. When I click the submit button the text in textfield is added to table. How can I after that reset the textfield back to empty??? It still contains the value which was added. I even tried with setdefaults which doesn't work???
| Code: |
$aFrmDefaults = array(
'txtType' => '',
'hidMisID' => '',
'hidMode' => 'create'
);
$oForm->setDefaults($aFrmDefaults); |
Even that doesn't overwrite the value???
Thanks for your help.[/code] |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1002
|
Posted: Tue Jul 15, 2008 10:16 am Post subject: |
|
|
| There is a hack that clears the form, but the clean solution is to make a header('Location: http://www.example.com/your/script.php'); redirect to the page that contains the form. This also ensures (better: tries to ensure) that the data isn't submitted twice. |
|
| Back to top |
|
 |
SanderK
Joined: 01 Jul 2008 Posts: 13
|
Posted: Tue Jul 15, 2008 11:47 am Post subject: |
|
|
| Thx...the location was also my solution for the moment. But I don't like it so much because I want to send the state like 'Record saved' etc.. And to pass this through request seems to me pretty lame. |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1002
|
Posted: Tue Jul 15, 2008 6:51 pm Post subject: |
|
|
Actually I wouldn't call it lame. In case of an error (either from form validation or e.g. because the database server isn't reachable), you wouldn't redirect, but show a message directly above the form. If you redirect only on success, you have only two cases: initial visit or the form was (successfully) submitted. I wouldn't use a parameter like "?msg=success", but maybe something short like "?s=1" (s for "submitted").
If you still don't like this approach, then use the hack:
(needs to be called before initializing QF the second time, i.e. for the "fresh" and empty form) |
|
| Back to top |
|
 |
SanderK
Joined: 01 Jul 2008 Posts: 13
|
Posted: Wed Jul 16, 2008 2:30 am Post subject: |
|
|
I'm going to try that hack. That will probably solve my problem. I actually do it like "?msg=1" at the moment. But I still think it is lame because you can actually go to the page and display a message without doing something.
Thanks for your help. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|