Getting button pressed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jodleren

    Getting button pressed

    Hi

    It is late and I am tired. I cannot remember how to check which of my
    buttons on the form was pressed. There are all submit's.

    Like

    echo "P=".$_POST['btn_post1']; // and eventually using isset()

    But how was it it was?
  • The Natural Philosopher

    #2
    Re: Getting button pressed

    jodleren wrote:
    Hi
    >
    It is late and I am tired. I cannot remember how to check which of my
    buttons on the form was pressed. There are all submit's.
    >
    Like
    >
    echo "P=".$_POST['btn_post1']; // and eventually using isset()
    >
    But how was it it was?
    Unless you use javascript with 'onclick' to set a hidden variable, I
    don't think there is a way of working out which submit button was pressed.

    Comment

    • Jerry Stuckle

      #3
      Re: Getting button pressed

      jodleren wrote:
      Hi
      >
      It is late and I am tired. I cannot remember how to check which of my
      buttons on the form was pressed. There are all submit's.
      >
      Like
      >
      echo "P=".$_POST['btn_post1']; // and eventually using isset()
      >
      But how was it it was?
      >
      The contents of $_POST['btn_post1'] will contain the contents of the
      value= parameter of the pressed button.

      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • macca

        #4
        Re: Getting button pressed

        If I have a form

        <form action="<?php $_SERVER['PHP_SELF'] ?>" method="get">

        <input type="submit" name="sub" value="Submit1" />
        <input type="submit" name="sub" value="Submit2" />

        </form>


        I could check which one was submitted using the value.

        e.g.

        if (isset($_GET['sub']) && $_GET['sub'] == 'Submit1'){

        echo 'Submit1 was pressed';

        } elseif (isset($_GET['sub']) && $_GET['sub'] == 'Submit2'){

        echo 'Submit2 was pressed';

        }

        Comment

        • macca

          #5
          Re: Getting button pressed

          <form action="<?php $_SERVER['PHP_SELF'] ?>" method="get">

          That should be <?php echo $_SERVER['PHP_SELF'] ?of course, before
          anyone comments... ;-)

          Comment

          • Michael Fesser

            #6
            Re: Getting button pressed

            ..oO(The Natural Philosopher)
            >jodleren wrote:
            >Hi
            >>
            >It is late and I am tired. I cannot remember how to check which of my
            >buttons on the form was pressed. There are all submit's.
            >>
            >Like
            >>
            >echo "P=".$_POST['btn_post1']; // and eventually using isset()
            >>
            >But how was it it was?
            >Unless you use javascript with 'onclick' to set a hidden variable, I
            >don't think there is a way of working out which submit button was pressed.
            Of course there is. Just give it a name and its value will be sent to
            the server if you activate the button.

            Micha

            Comment

            • The Natural Philosopher

              #7
              Re: Getting button pressed

              Michael Fesser wrote:
              .oO(The Natural Philosopher)
              >
              >jodleren wrote:
              >>Hi
              >>>
              >>It is late and I am tired. I cannot remember how to check which of my
              >>buttons on the form was pressed. There are all submit's.
              >>>
              >>Like
              >>>
              >>echo "P=".$_POST['btn_post1']; // and eventually using isset()
              >>>
              >>But how was it it was?
              >Unless you use javascript with 'onclick' to set a hidden variable, I
              >don't think there is a way of working out which submit button was pressed.
              >
              Of course there is. Just give it a name and its value will be sent to
              the server if you activate the button.
              >
              Oh? Never thought thought of naming a _submit_ button..

              I gave up on em..they look too clunky..I always use javascript instead
              on custom buttons..


              Micha

              Comment

              • Captain Paralytic

                #8
                Re: Getting button pressed

                On 25 Aug, 22:28, macca <ptmcna...@goog lemail.comwrote :
                <form action="<?php $_SERVER['PHP_SELF'] ?>" method="get">
                >
                That should be <?php echo $_SERVER['PHP_SELF'] ?of course, before
                anyone comments...    ;-)
                Or even just:
                <form action="" method="get">

                Comment

                • Michael Fesser

                  #9
                  Re: Getting button pressed

                  ..oO(The Natural Philosopher)
                  >Michael Fesser wrote:
                  >.oO(The Natural Philosopher)
                  >>
                  >>Unless you use javascript with 'onclick' to set a hidden variable, I
                  >>don't think there is a way of working out which submit button was pressed.
                  >>
                  >Of course there is. Just give it a name and its value will be sent to
                  >the server if you activate the button.
                  >>
                  >Oh? Never thought thought of naming a _submit_ button..
                  It's just another form control, nothing special.
                  >I gave up on em..they look too clunky..I always use javascript instead
                  >on custom buttons..
                  No need for unreliable JS. <buttonand <input type="image"exi st.

                  Micha

                  Comment

                  Working...