SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    377
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Best way to send user to url based on selected values?

    I have a form which contains a few drop down lists.
    The contents of the dropdown lists are dependent on each other and are populated via php scripts which are called each time a selection is made or changed by the user.

    When the view results button is clicked in the form I need the user to be directed to a specific page based on the selections they have made.

    The url of the page they need to be directed to is really based on what has been chosen in the first dropdown. The subsequent dropdowns form variables that I need to be sent to the page so that the data the user sees on that page is relevant.

    ie if the user has chosen bikes then a specific manufacturer then a specific price range the page they will be sent to will be the bike.php page with all the manufacturer specific bikes in their chosen price range visible. Can anyone tell me the best way to go about doing this please?

    I had thought about using the php header script along with an if statement but how do I then go about getting the variables sent to the page to be recognised?

    Would I be better looking at the window.location in js to do this?

    Any help and advice would be greatly appreciated on this. I can post the code for the form if that makes any difference.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by sketchgal View Post
    if the user has chosen bikes then a specific manufacturer then a specific price range the page they will be sent to will be the bike.php page with all the manufacturer specific bikes in their chosen price range visible. Can anyone tell me the best way to go about doing this please?
    There is a PHP server variable called QUERY_STRING that you can use when redirecting the page.

    For example, something like this:

    Code php:
    $bike = filter_input(INPUT_GET, 'bike', FILTER_SANITIZE_STRING);
    header($bike . '.php?' . $_SERVER['QUERY_STRING']);
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    377
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Thanks for the reply Paul but I don't understand how to use what you've suggested. The form currently has 3 dropdown boxes. The first is populated with the options that determine the url the user will be directed to when they click the form button.

    The second is a list of makes which is populated once the user makes a selection from the first drop down.

    The third is populated based on the selection in the second select.

    Each time a selection is made the form also has a results box which updates with the number of results found in the db matching the users choices in the form.

    How can I get the user to be sent to the correct page when the form button is clicked?
    I will also need to send the variables so that the correct results are shown on this final page.

    The code I was trying to use is below. Can someone please tell me why the following code is not working or how to implement what Paul has suggested?

    I'd be very greatful of any help with this.

    Code JavaScript:
    function goToStock(){
    	if (document.getElementById('top_search').value == "used") {
    		location.href='http://www.mysite.co.uk/used-cars/';
    	}
    	else if (document.getElementById('top_search').value == "van") {
    		location.href='http://www.mysite.co.uk/used-vans-trucks/';
    	} 
    	else if (document.getElementById('top_search').value == "bike") {
    		location.href='http://www.mysite.co.uk/used-bikes/';
    	} 
    	else if (document.getElementById('top_search').value == "nearlynew") {
    		location.href='http://www.mysite.co.uk/nearly-new-cars/';
    	} 
    	else if (document.getElementById('top_search').value == "motability") {
    		location.href='http://www.mysite.co.uk/motability/';
    	} 
    }

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    If you want to do it from javascript, you can set the form.action attribute to the page you want the form to be submitted to. That way, the submit event for the form will be to the different page that you set in the action property.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •