SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    USA
    Posts
    1,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how do you make a "Cancel" button for forms?

    I need to make a cancel button for the form - a button that goes to another page without processing form.

    Thanks for your help.

  2. #2
    SitePoint Wizard
    Join Date
    Jan 2004
    Location
    3rd rock from the sun
    Posts
    1,005
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Might depend on what you mean by "cancel".

    If its "restore the form to the state it was in when the page loads" youre looking for the straight html RESET in the form. <input type=reset> This in effect is often named "abandon changes" or similar.

    If thats not what you mean but some other "go back" action, well its either go back to the server and do a "Header : Location ..." php redirect, or if a JS history.go(-1) type of thing which you'll find in the JS forum I guess..

    Else what do you want cancel to do exactly?

  3. #3
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,426
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    HTML Code:
    <form action="formmail.php" method="post">
    ....
    <input type="submit" name="submitted" value="cancel">
    <input type="submit" name="submitted" value="don't cancel">
    </form>
    PHP Code:
    if ($_GET['submitted'] == "cancel")
    {
        
    header("Location: cancel.php");
    }
    ... 
    Real basic but it should give you the idea.

  4. #4
    SitePoint Wizard
    Join Date
    Jan 2004
    Location
    3rd rock from the sun
    Posts
    1,005
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @webdevguy et al
    Sorry I didnt read that properly.... "a button that goes to another page without processing form."

  5. #5
    SitePoint Wizard dreamscape's Avatar
    Join Date
    Aug 2005
    Posts
    1,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if your buttons are images, you can just put a link on the image to the "cancel" page. Not sure why you would POST only to destroy the data and go to another page when you can just outright link to another page.

  6. #6
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    USA
    Posts
    1,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what does it matter if I POST or GET.

    I think stymiee's will work great in that I will just POST then check the submitted value.

    I've been using PEAR Quickform and am going to start rolling my own. Take a look at this link for form submission security - good stuff:
    http://phpsec.org/projects/guide/2.html

    Thanks to everyone.

  7. #7
    SitePoint Evangelist Rodney H.'s Avatar
    Join Date
    Sep 2005
    Location
    Chicago, IL
    Posts
    479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can also make a cancel button like this, using the onClick JS event:
    HTML Code:
    <form name="form" method="post" action="process.php">
    <input type="submit" name="submit" value="submit" />
    <input type="button" name="cancel" value="cancel" onClick="window.location='http://yoursite.com/index.php';" />
    </form>

  8. #8
    SitePoint Wizard dreamscape's Avatar
    Join Date
    Aug 2005
    Posts
    1,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WebDevGuy
    what does it matter if I POST or GET.
    Why would you POST data just to destroy it on the server and send a redirect? When a normal link is what you want.

    POSTing data just to destroy it and redirect just wastes bandwidth.

  9. #9
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,426
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by dreamscape
    Why would you POST data just to destroy it on the server and send a redirect? When a normal link is what you want.

    POSTing data just to destroy it and redirect just wastes bandwidth.
    You can also make the cancel button a form upon itself and submit no data and then let php make the redirect. That way no javascript is used which may be truned off.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •