Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Passing form data in URL using post method

  1. #1
    Join Date
    Jan 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Passing form data in URL using post method

    Hi all,

    I am trying to pass data from a form field (to help adsense target ads) and I am running into a wall. I know it should not be that hard and there should be a script that can help.

    Anyway, here's the scoop. Normal form, using the POST method. I just want to take a form field (which will be the name of a state) and add it into the URL when the user clicks on submit.

    Anyone have any pointers or examples? Thank you in advance.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I don't know/think there's a way to do half of a form as post and half as get.

    But.... you could try javascript.

    Maybe something like:
    onSubmit="this.action=this.action+'?fieldname='+fieldname.value", though I'm not sure it that works or if it even could work.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I think that would work as long as the code was written correctly. It might have to trigger off of something other than onsubmit as well, in order for the change in the value of the action attribute to occur in time to be useful. If that were to be the case, perhaps the onchange event of the element whose value you wanted to pass along would work out. It would, of course be a javascript only solution though.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Works pretty well actually, with one minor addition(red):

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    </head>
    <body>
    <form action="some.htm" method="post" onsubmit="this.action=this.action+'?bob='+this.bob.value">
    <input type="text" name="bob"><input type="submit" value="GO">
    </form>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Actually, when referring to the element within that element you don't even have to use "this":
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    </head>
    <body>
    <form action="some.htm" method="post" onsubmit="action=action+'?bob='+bob.value">
    <input type="text" name="bob"><input type="submit" value="GO">
    </form>
    </body>
    </html>
    - Mike

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Could conflict in certain situations and might not work so well in older browsers unless the this keyword is used. Your idea did work fine in the few modern browsers I just tested it in.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    It obviously won't work externally, say defining this as document, which will cause an error, so like I said; It only works within an object, but just to be safe, you might as well put the "this" in there.
    - Mike

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Ha, glad it works. Maybe I'm finally getting the hang of JS.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Lol, were in opposite positions, I think I'm just starting to get the hang of PHP
    - Mike

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I'll trade you
    Off to AIM!
    (If you have AIM... //checking profile...)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •