Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reset Form - Goto Page 2

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
I have a form with a button on it, it clears the fields of a form. Can I direct the page its on to another one once the form is cleared with the same button?

<input type="reset" value=" Cancel " style="font-weight: 700"></font></p>

The Page I want it to goto is cancel.php

Many thanks
 
WHy would you even need to clear the form if you're going to redirect them to another form anyway? Just use a regular button instead of a reset button, and make the onclick event redirect to the other page:
Code:
<input type="button" name="cancel" onclick="documention.location.href="cancel.php">

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Many thanks Tracy. I am wanting to clear the form entries and then goto another page where the PHP variables are cleared. Comming from VB I miss not having the onclick properties where I could clear the variables as well, or can I?
 
Hello again,

I tried it and is did not work. It might be because the page/form is Posted?? I had no selection of "button" in the properties of the button, it was a modified submit button.

I tried changing the input type to button but it still did not work. Any ideas? Thanks



<form method="POST" action="EnterVariables.php">

Code etc

<input type="submit" value="Accept Selection"></p>
<p align="center">
<input type="reset" value="Clear" onclick="documention.location.href="Menul.php">
 
W3.org said:
reset buttons: When activated, a reset button resets all controls to their initial values.
As you can see, reset button does reset to initial values, but shouldn't be used for redirecting, like you're doing. Tracy's question is still very valid though: Why do you need to clear the values, if you're redirecting. Because of discontinuity of web application, all values will be lost anyway when you redirect. So it is just adding an additional task that is not necessary.
 
Thanks Vragabond. I have a form which has several text boxes for quantities of items. They are put into session variables (PHP). If a user goes back into the form, the boxes still have the values in, ie the user can check the values they entered. The person may also change their mind ans simply want to clear the form and go to another form. I need therfore somewhere along the line to clear/remove the session variables. To direct it to another page, and clear the fields is needed and not a wasted task. Thanks again
 
Actually, you do not need a reset button as such. You need a button that will redirect you to a php script that will clear session variables for that form. The reset button you've set up would not do what you want and would as such mislead the users. In HTML, form is filled with prefilled values or empty values when page is loaded. When user is filling out the form and before they push submit, there is no interaction with the server. Reset is a client side command, that deletes all info (all returns it to a prefilled value state) on the form. It does not interact and will not do anything on the server (where session variables are stored). It would be possible to reset all the values, then submit the form and fill the session values with the reset values (i.e. blank), but that would just overcomplicating things and wouldn't work with checkboxes. That way you should simply have a button called reset pointing to a php script that will unset the session variables.
 
Thankyou Vragabond. Yes you are correct as I just found out - the variables on the server need nulling or whatever. So I need two buttons, One to Submit and One to cancel and goto a page to unset variables. However I still cannot seem to add a second button. I have tried the code within and outside the form, both with problems. Any ideas? Thanks.


This is the original working submit button for the form posting:

<br><input type="submit" value="Accept"><br>


This is the one I've tried in/out of the form:

<input type="button" name="cancel" onclick="documention.location.href="Clear1.php" value="cancel">

I also tried removing the value "cancel" to match Tracy's code but that left no name on the button.

Regards

 
documentation should be document as a top entity in the DOM. However, this solution relies on JavaScript and should be avoided. Since JS is client-side and can be turned off by users, things that can be accomplished without it are best done that way. Either make a regular link for cancelling (you can also style it to make it look almost like a button) or make another submit button and then check for what was pressed on the script page:
Code:
<input type="submit" name="accept" value="Accept" /><br />
<input type="submit" name="cancel" value="Cancel" /><br />
Both buttons will point to the page specified in the action attribute of the form tag and in that php you can check which button was pressed and act accordingly. If it was Accept, store values in session. If cancel, unset the session variables.
 
Many thanks Vragabond. Yes I will stay away from Java. Any hints on how I could establish whether it was a cancel or acceptance in the php form its posting to? Otherwise I will do your other suggestion, put a regular link to a cancellation page. Guess that might be the easiest and less complicated. A star for you, and I think Tracy as she started me down a road. Regards
 
Although checking in PHP for the button pressed falls out of the scope of this forum, I guess I will grace you with a reply. Provided you are using post method, in your php script you would do:
Code:
 if($_POST['cancel']
 {
   do your session unsetting
 }
 else // assume accept was pressed
 {
   do session setting
 }
 
Thankyou Vragabond, much appreciated. Best Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top