PHP >form action< containing GET variables

Discussion in 'Web Design and Development' started by TheReef, Dec 8, 2008.

  1. TheReef macrumors 68000

    TheReef

    Joined:
    Sep 30, 2007
    Location:
    NSW, Australia.
    #1
    Hi all,
    Haven't ran into this one before.
    I have been able to send data using POST to URLs with GET variables in them successfully.

    eg
    Code:
    <form action = "www.mysite.com?page=home">
    


    But when sending variables using GET it overwrites the variables I've hard coded into the form action.


    Any ideas? (I'm hoping it's something simple, preferably not using Javascript to set the URL).
    Thanks for any help!
     
  2. Aea macrumors 6502a

    Aea

    Joined:
    May 23, 2007
    Location:
    Denver, Colorado
    #2
    Code:
    <form action = "www.mysite.com">
    <input type="hidden" name="page" value="home" />
    
    Would be the lazy way to handle it ;)
     
  3. TheReef thread starter macrumors 68000

    TheReef

    Joined:
    Sep 30, 2007
    Location:
    NSW, Australia.
    #3
    I feel so stupid :p
    I was thinking there'd be a trick to avoid overwriting… :p

    Thanks!

    (Continuing the question - is there a quick way if the URL variables are not known?)
     
  4. SrWebDeveloper macrumors 68000

    SrWebDeveloper

    Joined:
    Dec 7, 2007
    Location:
    Alexandria, VA, USA
    #4
    With GET, the query string is not sent with the action. Meaning, you need to use hidden fields for all the additional URL arguments. Then they show up in the URL on the submit.

    To prevent users from knowing your GET variables, process then encrypt all arguments and values using sha1(), pass the encrypted string using a hidden form field with name set as "setvariables" or whatever, and value set as the encrypted string. Then on the page handling the form submission, decrypt $_GET['setvariables'] and split into an array using ? or & as separators and you've got your arguments back.

    -jim
     

Share This Page