How to insert GET variables into a HTML form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • steve2856
    New Member
    • Sep 2007
    • 9

    How to insert GET variables into a HTML form

    Thanks for the article. Actuall this deals with passing parameters from an HTML page to PHP and we are looking for the opposite. Passing parameters from a URL link TO an HTML form. Here is the code for the form we are trying to update and it is the hidden value of LEAD ID that we want passed to the form from the URL link.

    How could this be accomplished?

    Here is the HTML of our form:
    [code=html]
    <HTML>

    <body>
    <input type="hidden" value="xxxxx" name="Lead ID">
    <input type="hidden" value="John Doe" name="Rep">

    <div align="left">
    <table border="0" cellpadding="0" cellspacing="1" width="98%" height="246">
    <tr>
    <td width="106%" align="center" height="30" colspan="2"><b> <font face="Arial" size="3">CALL
    REPORT</font></b></td>
    </tr>
    <tr>
    <td width="29%" align="right" height="25"><fo nt face="Arial"><b >Contact:</b></font></td>
    <td width="77%" height="25">&nb sp;<input type="text" name="Contact" size="32">
    </td>
    </tr>
    <tr>
    <td width="29%" align="right" height="25"><fo nt face="Arial" color="#FF0000" ><b>Date Contacted:</b></font></td>
    <td width="77%" height="25">&nb sp;<input type="text" name="Date_Cont acted" onfocus="showCa lendarControl(t his);" size="20" />
    </td>
    </tr>
    <tr>
    <td width="29%" align="right" height="81"><fo nt face="Arial"><b >Comments/
    Interests:</b></font></td>
    <td width="77%" height="81">&nb sp;<textarea rows="3" name="Comments" cols="69"></textarea></td>
    </tr>
    <tr>
    <td width="29%" align="right" height="25"><fo nt face="Arial" color="#0000FF" ><b>Next Action Date:</b></font></td>
    <td width="77%" height="25">&nb sp;<input type="text" name="Next_Acti on_Date" onfocus="showCa lendarControl(t his);" size="20" />
    </td>
    </tr>
    <tr>
    <td width="29%" align="right" height="25"><fo nt face="Arial" color="#0000FF" ><b>Next
    Action Comment:</b></font></td>
    <td width="77%" height="25">&nb sp;<input type="text" name="Next_Acti on_Step" size="61">
    </td>
    </tr>
    </table>
    </div>
    <p style="margin-top: 15; margin-bottom: 10" align="center"> <input type="submit" value="Send"></p>
    </form>
    <p style="margin-top: 15; margin-bottom: 10" align="center"> &nbsp;</p>
    </body>
    </HTML>
    [/code]
    Last edited by Atli; Sep 6 '07, 04:03 PM. Reason: Added [code] tags
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi Steve.

    I moved your question into it's own thread in the PHP forum, where it is more likely to be read by our Experts.

    I've also added [code] tags to your post. All code should be encapsulated in code tags.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Using PHP, you could change your hidden <input> tag to look something like the this:
      [code=php]
      <input type="hidden" value="<?php echo $_GET['leadID']; ?>" name="Lead ID">
      [/code]

      This is assuming that your URL contains the GET variable 'leadID'. So your URL string would have to look something like this:
      Code:
      http://myserver.com/mypage.php?leadID=valueOfLeadID

      Comment

      • steve2856
        New Member
        • Sep 2007
        • 9

        #4
        I am using this also to pull a field called contact which contains the full name of a person. When it places the value in the text box, it only puts the first name and not the full name. Here is the code I am using for this:

        [code=php]<p><input type="hidden" value=<?php echo $_SERVER['QUERY_STRING']; ?></p>
        Contact: <input type="text" name="Contact" value=<? echo $_GET['contact'] ?>>[/code]


        Originally posted by Atli
        Using PHP, you could change your hidden <input> tag to look something like the this:
        [code=php]
        <input type="hidden" value="<?php echo $_GET['leadID']; ?>" name="Lead ID">
        [/code]

        This is assuming that your URL contains the GET variable 'leadID'. So your URL string would have to look something like this:
        Code:
        http://myserver.com/mypage.php?leadID=valueOfLeadID
        Last edited by Atli; Sep 6 '07, 08:53 PM. Reason: Added [code] tags

        Comment

        • ak1dnar
          Recognized Expert Top Contributor
          • Jan 2007
          • 1584

          #5
          Can you post the full URL string you used for this?

          Comment

          • steve2856
            New Member
            • Sep 2007
            • 9

            #6
            Variables1.php? contact=Mark%20 Twain

            Originally posted by ajaxrand
            Can you post the full URL string you used for this?

            Comment

            • ak1dnar
              Recognized Expert Top Contributor
              • Jan 2007
              • 1584

              #7
              Try urlencode() first. if not working please post back.

              Comment

              • steve2856
                New Member
                • Sep 2007
                • 9

                #8
                Originally posted by ajaxrand
                Try urlencode() first. if not working please post back.
                Is this the correct syntax:
                [code=php]
                <input type="text" name="Contact" value=<? echo $_GET[urlencode('cont act')] ?>>
                [/code]
                Last edited by Atli; Sep 6 '07, 08:52 PM. Reason: Added [code] tags

                Comment

                • steve2856
                  New Member
                  • Sep 2007
                  • 9

                  #9
                  Originally posted by ajaxrand
                  Try urlencode() first. if not working please post back.
                  I only get the problem of truncation when the variable is passed to a text field. It does not truncate when I just display the value on the screen. What would be the difference?

                  Comment

                  • Atli
                    Recognized Expert Expert
                    • Nov 2006
                    • 5062

                    #10
                    How is the URL string being generated?
                    Are the values being passed from a HTML form?
                    Or are you generating the URL with some PHP code and echoing it as a link? (Or redirecting perhaps?)

                    If it is being generated from a HTML form, consider changing the 'method' to POST, which is a far better method for passing on detailed information, such as full names.
                    You can access those values just like you would the GET values by using the $_POST array.

                    Comment

                    • steve2856
                      New Member
                      • Sep 2007
                      • 9

                      #11
                      Originally posted by Atli
                      How is the URL string being generated?
                      Are the values being passed from a HTML form?
                      Or are you generating the URL with some PHP code and echoing it as a link? (Or redirecting perhaps?)

                      If it is being generated from a HTML form, consider changing the 'method' to POST, which is a far better method for passing on detailed information, such as full names.
                      You can access those values just like you would the GET values by using the $_POST array.
                      The URL string is being placed as a hyperlink in an E-mail message. Once this link connects to the page, it displays information including the contact full name in a text box. For some reason, when I do this as just a display without populating a text box, all is fine.

                      Comment

                      • Atli
                        Recognized Expert Expert
                        • Nov 2006
                        • 5062

                        #12
                        I see.

                        This would be the line that is causing the problem?
                        [code=php]
                        <input type="text" name="Contact" value=<? echo $_GET['contact'] ?>>
                        [/code]

                        Try putting the value inside quote marks and see what that does. (And to follow the standards, close the tag as well).
                        [code=php]
                        <input type="text" name="Contact" value="<? echo $_GET['contact']; ?>" />
                        [/code]

                        If that doesn't work, you can try running it through the urldecode() function:
                        [code=php]
                        <input type="text" name="Contact" value="<? echo urldecode($_GET['contact']); ?>" />
                        [/code]

                        Comment

                        • steve2856
                          New Member
                          • Sep 2007
                          • 9

                          #13
                          Originally posted by Atli
                          I see.

                          This would be the line that is causing the problem?
                          [code=php]
                          <input type="text" name="Contact" value=<? echo $_GET['contact'] ?>>
                          [/code]

                          Try putting the value inside quote marks and see what that does. (And to follow the standards, close the tag as well).
                          [code=php]
                          <input type="text" name="Contact" value="<? echo $_GET['contact']; ?>" />
                          [/code]

                          If that doesn't work, you can try running it through the urldecode() function:
                          [code=php]
                          <input type="text" name="Contact" value="<? echo urldecode($_GET['contact']); ?>" />
                          [/code]
                          That did the trick...Thanks! !

                          Comment

                          • Atli
                            Recognized Expert Expert
                            • Nov 2006
                            • 5062

                            #14
                            Originally posted by steve2856
                            That did the trick...Thanks! !
                            Glad to hear it :)
                            Good luck with your project!

                            Comment

                            Working...