Results 1 to 7 of 7

Thread: get/post using form with ?var= in url

  1. #1
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default get/post using form with ?var= in url

    I'm puzzled.

    This isn't a big deal as it seems to be easy to work around... but...


    If I'm using method="get" for a form tag, then it ignores anything after the ?... meaning "index.php?var=1" just makes the next page "index.php", ignoring the var=1 part.
    However, a hidden input makes it easy enough to work around.

    But... if I'm using method="post", then that seems to work WITH the ?var=1 part, where the url WOULD be index.php?var=1.


    This is kinda puzzling. I haven't tested extensively, so I might be wrong.

    Is this some kind of safety precaution so the ?var=1 doesn't conflict with an input of "var" later on?

    What's up?

  2. #2
    Join Date
    Aug 2004
    Posts
    9,890
    Thanks
    3
    Thanked 964 Times in 953 Posts
    Blog Entries
    15

    Default

    Hmmm I'm not sure I understand your question- is your trouble just with the browser stripping the parameters off the URL on the next page after submission, versus you having trouble getting those parameters inside your PHP script (via $_GET[])?

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    Case 1:
    If POST is method for form, the next URL DOES have ?var=1.
    Case 2:
    If GET is method for form, the next URL DOES NOT have ?var=1.

    The php works fine.

  4. #4
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by ddadmin
    Hmmm I'm not sure I understand your question
    I believe what djr33 is trying to describe is markup along the lines of:

    HTML Code:
    <form action="/path/to/resource?existing=values">
      <div>
        <input name="control-name" type="text" value="">
        <!-- ... -->
        <input type="submit" value="Send">
      </div>
    </form>
    When submitted, he expects a request to a URL such as:

    &#160;&#160;http://www.example.com/path/to/resource?existing=values&control-name=data

    However, the preset query string is being removed, creating a request for:

    &#160;&#160;http://www.example.com/path/to/resource?control-name=data

    instead.

    Whilst I agree that this is bad (though not wrong) behaviour - I think user agents should append the form data - it's common. Using hidden form controls is the most reliable approach.

    Mike

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    that's exactly what I'm saying.

    so.. it's the browser, not php... makes sense.... it is the url you're sent to.. ok. not my coding either.. good.


    So... basically, the form overrides the ending after the ?..., so with GET it does that, but POST doesn't override it.

    Makes sense.

    thanks.


    and, yeah, seems weird. Any way around this? (yes, I've tried hidden values in the forms... that's fine...)

  6. #6
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33
    Any way around this?
    Other than hidden controls, no. We just have to live with it.

    Mike

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    Alright. Well... easy enough.

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
  •