Get form name / id ??

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

    Get form name / id ??

    I have a form

    <form name="jim" id="jim" .......... >
    .........
    </form>

    How do I get either the name or id from the form in PHP ?
    --

    Rick

    Digital Printing
    www.intelligence-direct.com - 01270 215550
  • Roy W. Andersen

    #2
    Re: Get form name / id ??

    Rick wrote:[color=blue]
    > I have a form
    >
    > <form name="jim" id="jim" .......... >
    > ........
    > </form>
    >
    > How do I get either the name or id from the form in PHP ?[/color]

    You don't, unless you add it as a hidden input or a get-variable.

    <input type="hidden" name="formname" value="myform">

    And just grab that from $_POST['formname'] in your script.


    Roy W. Andersen
    --
    ra at broadpark dot no / http://roy.netgoth.org/

    "Hey! What kind of party is this? There's no booze
    and only one hooker!" - Bender, Futurama

    Comment

    • Alvaro G Vicario

      #3
      Re: Get form name / id ??

      *** Rick wrote/escribió (Thu, 13 Jan 2005 12:48:44 +0000):[color=blue]
      > <form name="jim" id="jim" .......... >
      > ........
      > </form>
      >
      > How do I get either the name or id from the form in PHP ?[/color]

      The names are the keys in the $_GET or $_POST array.

      foreach($_POST as $key => $value){
      echo "<li>$key: $value</li>";
      }

      --
      -- Álvaro G. Vicario - Burgos, Spain
      -- Thank you for not e-mailing me your questions
      --

      Comment

      • Rick

        #4
        Re: Get form name / id ??

        Alvaro G Vicario wrote:
        [color=blue]
        > *** Rick wrote/escribió (Thu, 13 Jan 2005 12:48:44 +0000):[color=green]
        >> <form name="jim" id="jim" .......... >
        >> ........
        >> </form>
        >>
        >> How do I get either the name or id from the form in PHP ?[/color]
        >
        > The names are the keys in the $_GET or $_POST array.
        >
        > foreach($_POST as $key => $value){
        > echo "<li>$key: $value</li>";
        > }[/color]

        Thats only for inputs contained within a form

        --

        Rick

        Digital Printing
        www.intelligence-direct.com - 01270 215550

        Comment

        • Rick

          #5
          Re: Get form name / id ??

          Roy W. Andersen wrote:
          [color=blue]
          > Rick wrote:[color=green]
          >> I have a form
          >>
          >> <form name="jim" id="jim" .......... >
          >> ........
          >> </form>
          >>
          >> How do I get either the name or id from the form in PHP ?[/color]
          >
          > You don't, unless you add it as a hidden input or a get-variable.
          >
          > <input type="hidden" name="formname" value="myform">
          >
          > And just grab that from $_POST['formname'] in your script.[/color]

          Bugger, thats what I am doing at the moment, was hoping there was a better
          way :/

          --

          Rick

          Digital Printing
          www.intelligence-direct.com - 01270 215550

          Comment

          • Roy W. Andersen

            #6
            Re: Get form name / id ??

            Rick wrote:[color=blue]
            > Roy W. Andersen wrote:
            >[color=green]
            >><input type="hidden" name="formname" value="myform">
            >>
            >>And just grab that from $_POST['formname'] in your script.[/color]
            >
            > Bugger, thats what I am doing at the moment, was hoping there was a better
            > way :/[/color]

            Sending it as a POST with the rest of the form is pretty straight
            forward and simple. If you're doing a foreach() loop on the $_POST array
            on the serverside and don't want to do whatever you do to the form data
            with that field, just issue an if/else or switch-statement to filter it
            out. Either that, or you can start by grabbing the $_POST['formname']
            followed by an unset($_POST['formname']) to avoid it carrying into the
            code you got further down :)


            Roy W. Andersen
            --
            ra at broadpark dot no / http://roy.netgoth.org/

            "Hey! What kind of party is this? There's no booze
            and only one hooker!" - Bender, Futurama

            Comment

            • Alvaro G Vicario

              #7
              Re: Get form name / id ??

              *** Rick wrote/escribió (Thu, 13 Jan 2005 13:00:55 +0000):[color=blue]
              > Thats only for inputs contained within a form[/color]

              You are right, I misunderstood you. The answer is: you cannot. That info is
              not sent to the server. Just add an extra hidden field.

              --
              -- Álvaro G. Vicario - Burgos, Spain
              -- Thank you for not e-mailing me your questions
              --

              Comment

              • Michael Fesser

                #8
                Re: Get form name / id ??

                .oO(Rick)
                [color=blue]
                >Roy W. Andersen wrote:
                >[color=green]
                >> You don't, unless you add it as a hidden input or a get-variable.
                >>
                >> <input type="hidden" name="formname" value="myform">
                >>
                >> And just grab that from $_POST['formname'] in your script.[/color]
                >
                >Bugger, thats what I am doing at the moment, was hoping there was a better
                >way :/[/color]

                Nope. The name attribute for the form element is just there for
                backwards compatibility (according to the spec, personally I've never
                used it), so it's rather useless and not submitted to the server at all.

                Micha

                Comment

                Working...