Form Submit Button Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David T. Ashley

    Form Submit Button Question

    Hi,

    For a web page, I want a SUBMIT button that commits the form data and a
    CANCEL button that goes to a different target (i.e. a different script).

    I haven't figured out how to do this, because the <FORM ACTION="... tag
    seems to make sure that any two submit controls in a form have to go to the
    same target.

    BTW, the CANCEL button does not have to submit any form data.

    Thanks, Dave.



  • Juliette

    #2
    Re: Form Submit Button Question

    David T. Ashley wrote:
    Hi,
    >
    For a web page, I want a SUBMIT button that commits the form data and a
    CANCEL button that goes to a different target (i.e. a different script).
    >
    I haven't figured out how to do this, because the <FORM ACTION="... tag
    seems to make sure that any two submit controls in a form have to go to the
    same target.
    >
    BTW, the CANCEL button does not have to submit any form data.
    >
    Thanks, Dave.
    >
    >
    >
    You're on the right track.

    Submitting a form will *always* submit the form data, be grateful as
    that is what we will use.

    In your PHP script do something like:

    // Was the value of the submit button 'Submit' ?
    if( $_POST['submit'] === 'Submit') {
    // Process your form
    }
    // Was the value of the submit button 'Cancel' ?
    elseif( $_POST['submit'] === 'Cancel') {
    // Redirect to another page or include a different script or any other
    way you want to do your cancel action
    }

    Hope this helps !
    Grz, Juliette

    Comment

    • flamer

      #3
      Re: Form Submit Button Question


      David T. Ashley wrote:
      Hi,
      >
      For a web page, I want a SUBMIT button that commits the form data and a
      CANCEL button that goes to a different target (i.e. a different script).
      >
      I haven't figured out how to do this, because the <FORM ACTION="... tag
      seems to make sure that any two submit controls in a form have to go to the
      same target.
      >
      BTW, the CANCEL button does not have to submit any form data.
      >
      Thanks, Dave.
      javascript will do it.

      Comment

      • Chuck Anderson

        #4
        Re: Form Submit Button Question

        flamer wrote:
        David T. Ashley wrote:
        >
        >
        >Hi,
        >>
        >For a web page, I want a SUBMIT button that commits the form data and a
        >CANCEL button that goes to a different target (i.e. a different script).
        >>
        >I haven't figured out how to do this, because the <FORM ACTION="... tag
        >seems to make sure that any two submit controls in a form have to go to the
        >same target.
        >>
        >BTW, the CANCEL button does not have to submit any form data.
        >>
        >Thanks, Dave.
        >>
        >
        javascript will do it.
        >
        >
        To clarify that a bit more - do not put an action in the form tag. Use a
        Javascript Onclick event on each button to set form.action.

        The easiest method, however, since you do not need to submit any data on
        Cancel, is to simply use two forms.

        --
        *************** **************
        Chuck Anderson • Boulder, CO

        Everyone's journey should be different,
        so that we all are enriched
        in new and endless ways
        *************** **************

        Comment

        • David T. Ashley

          #5
          Re: Form Submit Button Question


          "Chuck Anderson" <websiteaddress @seemy.sigwrote in message
          news:xvmdnZvd3Z u1CDHZnZ2dnUVZ_ tCdnZ2d@comcast .com...
          >>
          >javascript will do it.
          >>
          >>
          To clarify that a bit more - do not put an action in the form tag. Use a
          Javascript Onclick event on each button to set form.action.
          The recommended Javascript worked great.

          Just one question ... my form buttons are "Change Password" and "Cancel", in
          that order. When I hit ENTER on the computer keyboard, both IE and Mozilla
          Firefox choose the "Change Password" button (I assume because it is the
          first button in the form).

          Is that the reason ENTER chooses one button (because it is first on the
          form)?

          Can this order or selection be modified?

          Thanks.



          Comment

          • flamer die.spam@hotmail.com

            #6
            Re: Form Submit Button Question

            no that is set in the browser, by default hitting enter is the same as
            pressing submit.. HOWEVER.. fyi: when you press submit in the POST data
            then $_POST[submit]=submit but if they press enter (only in IE) then
            $_POST[submit] is not set..

            thats off topic but can cause some confusion if in your scripts you use
            if (isset($_POST['submit'])) { process form }

            because if they hit enter rather than clicking submit then it wont be
            set ect.. (use a hidden form field and check if that is set instead)

            Flamer.

            David T. Ashley wrote:
            "Chuck Anderson" <websiteaddress @seemy.sigwrote in message
            news:xvmdnZvd3Z u1CDHZnZ2dnUVZ_ tCdnZ2d@comcast .com...
            >
            javascript will do it.
            >
            >
            To clarify that a bit more - do not put an action in the form tag. Use a
            Javascript Onclick event on each button to set form.action.
            >
            The recommended Javascript worked great.
            >
            Just one question ... my form buttons are "Change Password" and "Cancel", in
            that order. When I hit ENTER on the computer keyboard, both IE and Mozilla
            Firefox choose the "Change Password" button (I assume because it is the
            first button in the form).
            >
            Is that the reason ENTER chooses one button (because it is first on the
            form)?
            >
            Can this order or selection be modified?
            >
            Thanks.

            Comment

            • Juliette

              #7
              Re: Form Submit Button Question

              flamer die.spam@hotmai l.com wrote:
              no that is set in the browser, by default hitting enter is the same as
              pressing submit.. HOWEVER.. fyi: when you press submit in the POST data
              then $_POST[submit]=submit but if they press enter (only in IE) then
              $_POST[submit] is not set..
              >
              thats off topic but can cause some confusion if in your scripts you use
              if (isset($_POST['submit'])) { process form }
              >
              because if they hit enter rather than clicking submit then it wont be
              set ect.. (use a hidden form field and check if that is set instead)
              >
              Flamer.
              >
              David T. Ashley wrote:
              >
              >"Chuck Anderson" <websiteaddress @seemy.sigwrote in message
              >news:xvmdnZvd3 Zu1CDHZnZ2dnUVZ _tCdnZ2d@comcas t.com...
              >>>javascript will do it.
              >>>>
              >>>>
              >>To clarify that a bit more - do not put an action in the form tag. Use a
              >>Javascript Onclick event on each button to set form.action.
              >The recommended Javascript worked great.
              >>
              >Just one question ... my form buttons are "Change Password" and "Cancel", in
              >that order. When I hit ENTER on the computer keyboard, both IE and Mozilla
              >Firefox choose the "Change Password" button (I assume because it is the
              >first button in the form).
              >>
              >Is that the reason ENTER chooses one button (because it is first on the
              >form)?
              >>
              >Can this order or selection be modified?
              >>
              >Thanks.
              >
              Hmm.. don't know which version of IE you are using, but your comment
              made me test a private script which I until now had only used in FF.
              The script uses the $_POST['submit'] value to determine what to do as
              there are three different forms on the page.
              No matter which form I changed and then submitted with the ENTER button,
              the resulting page showed that the requested action had been properly
              taken, i.e. the value of the Submit button has been passed on properly.

              Tested with IE6.

              Grz, Juliette

              Comment

              • flamer die.spam@hotmail.com

                #8
                Re: Form Submit Button Question

                Juliette wrote:
                flamer die.spam@hotmai l.com wrote:
                no that is set in the browser, by default hitting enter is the same as
                pressing submit.. HOWEVER.. fyi: when you press submit in the POST data
                then $_POST[submit]=submit but if they press enter (only in IE) then
                $_POST[submit] is not set..

                thats off topic but can cause some confusion if in your scripts you use
                if (isset($_POST['submit'])) { process form }

                because if they hit enter rather than clicking submit then it wont be
                set ect.. (use a hidden form field and check if that is set instead)

                Flamer.

                David T. Ashley wrote:
                "Chuck Anderson" <websiteaddress @seemy.sigwrote in message
                news:xvmdnZvd3Z u1CDHZnZ2dnUVZ_ tCdnZ2d@comcast .com...
                >>javascript will do it.
                >>>
                >>>
                >To clarify that a bit more - do not put an action in the form tag. Use a
                >Javascript Onclick event on each button to set form.action.
                The recommended Javascript worked great.
                >
                Just one question ... my form buttons are "Change Password" and "Cancel", in
                that order. When I hit ENTER on the computer keyboard, both IE and Mozilla
                Firefox choose the "Change Password" button (I assume because it is the
                first button in the form).
                >
                Is that the reason ENTER chooses one button (because it is first on the
                form)?
                >
                Can this order or selection be modified?
                >
                Thanks.
                >
                Hmm.. don't know which version of IE you are using, but your comment
                made me test a private script which I until now had only used in FF.
                The script uses the $_POST['submit'] value to determine what to do as
                there are three different forms on the page.
                No matter which form I changed and then submitted with the ENTER button,
                the resulting page showed that the requested action had been properly
                taken, i.e. the value of the Submit button has been passed on properly.
                >
                Tested with IE6.
                >
                Grz, Juliette
                Ok must have been fixed then, because this test was <5.5
                untested on other browsers.

                Flamer.

                Comment

                Working...