PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Reset Form

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> HTML
View previous topic :: View next topic  
Author Message
SanderK



Joined: 01 Jul 2008
Posts: 13

PostPosted: Tue Jul 15, 2008 5:57 am    Post subject: Reset Form Reply with quote

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
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1002

PostPosted: Tue Jul 15, 2008 10:16 am    Post subject: Reply with quote

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
View user's profile Send private message
SanderK



Joined: 01 Jul 2008
Posts: 13

PostPosted: Tue Jul 15, 2008 11:47 am    Post subject: Reply with quote

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
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1002

PostPosted: Tue Jul 15, 2008 6:51 pm    Post subject: Reply with quote

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:
Code:
unset($_POST);

(needs to be called before initializing QF the second time, i.e. for the "fresh" and empty form)
Back to top
View user's profile Send private message
SanderK



Joined: 01 Jul 2008
Posts: 13

PostPosted: Wed Jul 16, 2008 2:30 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> HTML All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
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



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement

'Actiemonitor' online projectmanagement software