SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Oct 2005
    Posts
    288
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    detect cancel on form <input type="cancel"

    My form contains

    <fieldset id="choices">
    <legend>Action</legend>
    <input type="submit" name="save" value="Save" />
    <input type="reset" name="reset" value="Reset" />
    <input type="cancel" name="cancel" value="Cancel" />
    </fieldset> <!-- choices -->
    </form>
    The submit and reset work as expected.

    Interestingly, the submit and reset come up as buttons, but the cancel comes up as a box in Firefox/3.6.3 and IE 8.0.

    More important, how do I detect (and redirect) when user clicks the "cancel"?

    Regards,

    Grnadpa

    (Searched the archives -- must not be using correct keywords)

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    If you're using PHP:
    Code PHP:
    if (isset($_POST['cancel']))

  3. #3
    SitePoint Addict
    Join Date
    Oct 2005
    Posts
    288
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you for your prompt response.

    Only the type="submit" invokes the php.

    I can, of course, change the type="cancel" to type="submit" and check in my .php as you suggest. But thought there might be a detectable way to distinguish between the type="reset" and the type="cancel" without invoking (and complicating) the .php module.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    There is no such HTML as <input type="cancel">

    The only way you could set up a cancel button would be to either use a submit button and pass a different value to the server saying to cancel OR to use <input type="button"> with the cancel functionality attached using JavaScript.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    You know...there is zero need for a reset button. It is an accident wating to happen. Furthor more, why must the user hit "Cancel" to cancel? Could they just not submit the form and go some where else?
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  6. #6
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,283
    Mentioned
    51 Post(s)
    Tagged
    2 Thread(s)
    Stephen, there is no type="cancel" in the specs... but why does Jim Thatcher mention it?? Is it a mistake?
    http://jimthatcher.com/webcourse8.htm

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Stomme poes View Post
    Stephen, there is no type="cancel" in the specs... but why does Jim Thatcher mention it?? Is it a mistake?
    http://jimthatcher.com/webcourse8.htm
    That is a mistake. There are a number of new input types being introduced in HTML 5 and even HTML 5 does not have type=cancel. There is no such thing as type=cancel in any version of HTML. There is no need for it either since the easiest way to cancel a form is to just not press the submit button.

    Just to make things easier here's the complete list

    type=button
    type=checkbox
    type=color (HTML 5 only)
    type=date (HTML 5 only)
    type=datetime (HTML 5 only)
    type=datetime-local (HTML 5 only)
    type=emaiil (HTML 5 only)
    type=file
    type=hidden
    type=image
    type=month (HTML 5 only)
    type=number (HTML 5 only)
    type=password
    type=radio
    type=range (HTML 5 only)
    type=reset
    type=search (HTML 5 only)
    type=submit
    type=tel (HTML 5 only)
    type=text
    type=tiime (HTML 5 only)
    type=url (HTML 5 only)
    type=week (HTML 5 only)
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    The nearest to a 'cancel', would be the 'cancelable' value appears within XForms but that's beyond the scope of HTML. I suspect Jim was thinking of common text rather than "type" and got muddled.

  9. #9
    SitePoint Member
    Join Date
    May 2010
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    there is no cancel input type. you have to use submit instead of cancel and write onclick javascript function to redirect the page.

    I think this will help. if not sorry...

    all the best
    Kumar


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
  •