SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Append input name value to url string when posting

    Basically I have been asked by our systems guy here for the sake of analytics to add the value from a search to the url string so we can track the keywords searched.

    So i have the code below which works fine, but I dont know how to append the value of the input to the url string.

    Code:
        <form name="search" method="post" action="result_Search.php">    
        <input type="text" value="Search By Safe Hotels..." onfocus="this.value = (this.value == 'Search By Safe Hotels...') ? '' : this.value;" onblur="this.value = (this.value == '') ? 'Search By Safe Hotels...' : this.value;" style="position:relative; float:left; width:223px; margin-left:2px; height:21px; color:#000;" name="find" />
        
        <input type="image" src="site_images/search_Button_Little.png" alt="Submit Form" />
        <input type="hidden" name="searching" value="yes" />
        </form>
    So for instance, if the user enters 'bristol' in to the search, when they click submit the url will be liek this:

    result_Search.php?Search=Bristol

    So its getting the value out of the input name title 'find' and adding it to the url.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by multichild View Post
    So its getting the value out of the input name title 'find' and adding it to the url.
    Currently you are using the POST method to submit the form data. If you want the data to be in the url, then you can use the GET method to submit the form data instead, and adjust your PHP script to retrieve the info accordingly.

    HTML Code:
    <form name="search" method="get" action="result_Search.php">
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Paul,

    Good to hear form you again.

    Thats part of the problem really, as putting the value in the url has no benefit to the site, only in an analytics sense.

    The whole site is set up to deal with POST and so ideally, I need to keep it like that, but for analytics reasons have the value also in the URL.

    Cheers

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by multichild View Post
    The whole site is set up to deal with POST
    There are other solutions - such as submit the form to an intermediary page via GET, which can then automatically redirect to a submit via POST while keeping the values in the URL.
    Or, you can submit via POST and have the server-side script redirect to the same page with the values in the URL.

    IMHO though the easiest solution is to submit via GET, from where you can then direct the information to where it needs to be.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Quote Originally Posted by multichild View Post
    Thats part of the problem really, as putting the value in the url has no benefit to the site, only in an analytics sense.
    It also benefits your users, as with the params in the URL they can bookmark a particular search and return to it later (or share it with someone else).

  6. #6
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    915
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes thank you,

    I'm glad also that there isnt a sort of easy way that I missed.

    Will look into this and like fretburner syas its also good for bookmarking, so will mention it to the systems guy.

    Thanks guys

  7. #7
    SitePoint Addict SLEE's Avatar
    Join Date
    Aug 2003
    Location
    uk
    Posts
    258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    forgive me if this beyond the scope of this but thought it would be worth a mention.
    ideally what you want is to use GET and then on the server have it change the URL to be www.yoursite.com/bristol or maybe www.yoursite.com/search/bristol
    this makes it much easier for a user and still good for search engines


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
  •