Find element name based on value match

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Inge Jones
    New Member
    • Mar 2007
    • 4

    Find element name based on value match

    I have a form that dynamically generates Submit buttons. I want all the buttons to display the same text "More info" while their names are dynamically generated numeric names (they point to database record numbers).

    Obviously when the form returns, only one button will have been clicked. So I want to look in $_POST for a value "More info" and then ask the name of the button! The integer value of the name will be the record I display to the user, containing the More info they wanted. I have this working fine the other way round - when the value is the record number (ie the record number shows on the button face) - but I don't want the numbers showing.

    So my question is, how can I get the name of a form element returned, based on finding an element in the $_POST array with the desired value?
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    This is exactly a crap, i can't understand anything make it in to steps.

    As i feel. you are going to populate a button for more info based on a record.
    then once you click the button another button will display. ok fine.
    in that button face do you need to print some thing. ?

    Please :)

    Comment

    • Inge Jones
      New Member
      • Mar 2007
      • 4

      #3
      I will be displaying a form, which contains a table, and in each row of the table is just a few fields from a record. The records that are shown will depend on what the user searched for.

      When the user sees a record that looks like what he needs, he should be able to click a button to view the whole of that record. A button is generated on each row of the table.

      At this time, I have all the buttons named "MoreInfo", and I have the record number showing on the button, because I am defining that as the "value". I test the value of $_POST['MoreInfo'] and open that record. This is working very well.

      However, I don't want the record number showing on the button, I want the button to say "More Info". So I would therefore like to give each button the "value" of "More Info" and the "name" of $recordnumber

      Comment

      • ak1dnar
        Recognized Expert Top Contributor
        • Jan 2007
        • 1584

        #4
        If you can print multiple forms like this you can made it.
        print the value=" here " in hidden fields.

        [PHP]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Untitl ed Document</title>
        </head>

        <body>
        <!-- wrap your <TR> with Forms and Dynamically print this value = " echo ID here "-->
        <form action="more.ph p" method="post" name="more">
        <input name="info" type="hidden" value="1001"/>
        <input type="submit" value="More Info"/>
        </form>
        <BR>
        <form action="more.ph p" method="post" name="more">
        <input name="info" type="hidden" value="1002"/>
        <input type="submit" value="More Info"/><BR>
        </form>
        </body>
        </html>[/PHP]

        more.php
        [PHP]<?
        $more_info = $_POST['info'];
        echo $more_info;
        ?>[/PHP]

        Comment

        • Inge Jones
          New Member
          • Mar 2007
          • 4

          #5
          Thanks, that's a way round it. So are you saying it is *not* possible to deduce the name of a form element from the $_POST array? It seemed to me that would be more direct and efficient, if it was possible.

          Comment

          • Inge Jones
            New Member
            • Mar 2007
            • 4

            #6
            Actually sorry I have just realised I cannot use that. All the buttons must be on the same form as there is tons of other stuff I need to transmit, such as what the search terms were, the filter chosen, the number of records already shown etc. In fact that's why I am trying to use submit buttons instead of having "more info..." links - because of the large amount of data I would have to include in that link. After the user finishes with the individual record, they are supposed to go back to their filtered list to carry on browsing.

            Comment

            • ak1dnar
              Recognized Expert Top Contributor
              • Jan 2007
              • 1584

              #7
              Originally posted by Inge Jones
              Actually sorry I have just realised I cannot use that. All the buttons must be on the same form as there is tons of other stuff I need to transmit, such as what the search terms were, the filter chosen, the number of records already shown etc. In fact that's why I am trying to use submit buttons instead of having "more info..." links - because of the large amount of data I would have to include in that link. After the user finishes with the individual record, they are supposed to go back to their filtered list to carry on browsing.
              Happy Coding !
              thread is open for you. either me or these guys will help you. give it a try. ;)

              Comment

              Working...