Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,127
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Submitting Form changes Query String in URL

    My website has a Subsection landing page which lists Article Summaries (i.e. Title, Thumbnail, Short Summary).

    Because this listing will continue to grow over time, I am adding Sorting to the page as well as Pagination.

    Currently I have a single drop-down call "Sort By" with choices like this...
    Code:
    Date (Newest to Oldest)
    Date (Oldest to Newst)
    Title (A to Z)
    Title (Z to A)
    Rating (Highest to Lowest)
    Rating (Lowest to Highest)

    Here is what I need help with...

    After a user selects a choice above, and clicks on the "Go" command button, I want to somehow take the sort criteria and place it into the Query String.


    Here is how I expect the URL + Query String to look...
    Code:
    www.debbie.com/finance/markets/?sortname=by-date&sortdir=desc&page=1
    I spent all of this time re-tooling how my URL looks to maximize SEO, and so I want the URL + Query String to look like above so Google can use that to crawl my website.


    (**BTW, I do NOT want to use JavaScript. Period!)


    In January I create a Private Message module which had sorting on each column in the Inbox. To handle the sorting there, I just used PHP to toggle whether an up-arrow or down-arrow appeared, and behind the icon was a hyperlink, so creating a Query String was easy in that case.

    However, I am really lost as to how I can take a Form submission - and either a GET or POST request - and use that data to build the Query String?!


    Certainly this must be a common problem for which there is already an eloquent - and secure - solution?!

    Your help is appreciated!

    Sincerely,


    Debbie
    Last edited by doubledee; 05-05-2014 at 11:09 PM.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,354
    Thanks
    23
    Thanked 618 Times in 617 Posts
    (**BTW, I do NOT want to use JavaScript. Period!)
    You do know that JS and CSS is the future of the internet and the way things will be, and are now, done?

    Anyway is this close to what your looking for?
    PHP Code:
    <?php
    if(isset($_GET["Lag"]) && ($_GET["Lag"] == "bigger" )){
        
    $temp $_GET["ray"];

        switch (
    $temp) {
          case 
    "N2O":
            
    header("Location: https://www.google.com/");
            break;
          case 
    "O2N":
            
    header("Location: www.debbie.com/finance/markets/?sortname=by-date&sortdir=desc&page=1");
            break;
          case 
    "A2Z":
            echo 
    "A2Z here";
            break;
          case 
    "Z2A":
            echo 
    "Z2A here";
            break;
          case 
    "H2L":
            echo 
    "H2L here";
            break;
          case 
    "L2H":
            echo 
    "L2H here";
            break;
          default:
            echo 
    "All is lost";
        }
    }
    ?>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta charset="UTF-8" />
    <title>Title of the document</title>
    </head>

    <body>

    <form method="get" action="">
    <input type="hidden" name="Lag" value="bigger">
        <select name="ray">
            <option value="N2O">Date (Newest to Oldest)</option>
            <option value="O2N">Date (Oldest to Newst)</option>
            <option value="A2Z">Title (A to Z)</option>
            <option value="Z2A">Title (Z to A)</option>
            <option value="H2L">Rating (Highest to Lowest)</option>
            <option value="L2H">Rating (Lowest to Highest)</option>
        </select>
        <input type="submit" />
    </form>

    </body>
    </html>
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,127
    Thanks
    27
    Thanked 0 Times in 0 Posts
    sunfighter,

    What is "Lag" and "Ray"???


    Debbie

  • #4
    Regular Coder
    Join Date
    Sep 2002
    Posts
    462
    Thanks
    0
    Thanked 20 Times in 20 Posts
    Code:
    if(isset($_POST['formname']) && $_POST['formname']=='sortform'){
    
    
    $Query  = "Select * FROM yourtable ";
    $Query .= "ORDERBY $_POST['orderby'] $_POST['direction']";
    
    }
    
    <form action="#" method="post">
    <input type="hidden" name="formname" value="sortform" >
    OrderBy:
    <select name="orderby">
    <option>Date</option>
    <option>Title</option>
    <option>Rating</option>
    </select>
    
    Direction:
    <input type="radio" name="direction" value="asc" />Ascending<br />
    <input type="radio" name="direction" value="dec" />Decending
    
    <input type="submit" value="Sort">
    </form>
    Doing away with the "pretty urls"?
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.

  • #5
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,127
    Thanks
    27
    Thanked 0 Times in 0 Posts
    [QUOTE=c1lonewolf;1396525]
    Code:
    if(isset($_POST['formname']) && $_POST['formname']=='sortform'){
    
    
    $Query  = "Select * FROM yourtable ";
    $Query .= "ORDERBY $_POST['orderby'] $_POST['direction']";
    
    }
    
    <form action="#" method="post">
    <input type="hidden" name="formname" value="sortform" >
    OrderBy:
    <select name="orderby">
    <option>Date</option>
    <option>Title</option>
    <option>Rating</option>
    </select>
    
    Direction:
    <input type="radio" name="direction" value="asc" />Ascending<br />
    <input type="radio" name="direction" value="dec" />Decending
    
    <input type="submit" value="Sort">
    </form>
    Not sure what that code is...



    Quote Originally Posted by c1lonewolf View Post
    Doing away with the "pretty urls"?
    Somewhat. I am keeping the base pretty URL, but converting the pretty sorting URL and making it a Query String for SEO reasons.


    Debbie

  • #6
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,354
    Thanks
    23
    Thanked 618 Times in 617 Posts
    The code didn't work for you Deb?
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #7
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,127
    Thanks
    27
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sunfighter View Post
    The code didn't work for you Deb?
    I didn't understand your funky variable names and use of hidden. (Thought maybe it was a secret message to me?!)

    As far as your code...

    I had to tweak some things, but in the end you get the golden prize!!

    (At first I was a little nervous of your use of redirects, but I did some Googling and pondering, and based on where I placed your code in my script, I feel that the redirects are completely protected from hacking.)

    Took a little thinking of how to get a sticky drop-down to work, but I just fixed that one using a $_SESSION.

    Still testing, but as far as I can see, things work exactly as I wanted AND I didn't have to use dirty JavaScript!!

    Thanks for your help!!!

    Sincerely,


    Debbie

  • #8
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,127
    Thanks
    27
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sunfighter View Post
    You do know that JS and CSS is the future of the internet and the way things will be, and are now, done?
    Yeah, except for...

    1.) Most developers don't know how to use JavaScript properly

    2.) Most websites on the Internet look like crap thanks to *retarded* over-use/misuse of JavaScript

    3.) JavaScript introduces a large security threat when not done correctly

    4.) JavaScript - AFAIK - doesn't work on tablets and mobile

    5.) 90% of what people use JavaScript for can be just as well without it

    6.) My website is every bit as "dynamic" and "interactive" as most, and I haven't used a lick of JavaScript on my website

    7.) JavaScript just adds another layer of complexity to your code-base that often isn't needed. Why do something in 50 lines of code when 5 lines will do?

    8.) For v3.0, I will probably break down and learn JavaScipt, but it has in no way, shape, or form impeded me in building the website of my dreams...

    Sincerely,


    Debbie

  • #9
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,354
    Thanks
    23
    Thanked 618 Times in 617 Posts
    Not sure I agree with all your reasons on not using JS, but in the end it's all up to you. Some points are right on.
    As for
    PHP Code:
    if(isset($_GET["Lag"]) && ($_GET["Lag"] == "bigger" )){ 
    A wise man on this site brought this up ages ago and I have used it in my programming when I attach a php script to the top of a HTML. If I call another file(PHP) I don't think I need it. Here's the explanation.
    The PHP code has to be a block or it will execute as soon as the page loads. Most examples on the internet use <input type="submit" name="submit" /> and if(isset($_GET["submit"])){ to do this, but our guru says older I.E. browsers don't understand this. That's the $_GET["submit"] part. I think the newer versions do, but never have checked.
    His solution was to use a hidden field as I have. The "Lag" and "bigger" were made up on the spot and have no significance at all except the to mask the filly dirty one I use; "micro$" and "junk" and "junk" is a substitution.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #10
    Regular Coder
    Join Date
    Oct 2004
    Posts
    363
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Just use standard links then style it however you want.
    Code:
    div#sorting li
    {
    	display:none;
    }
    div#sorting:hover li
    {
    	display:block;
    }
    Code:
    <div id="sorting">
        <h3>Sort</h3>
        <ul>
             <li><a href="/finance/markets/?sortname=by-date&sortdir=asc&page=1">Date (Newest to Oldest)</a></li>
             <li><a href="/finance/markets/?sortname=by-date&sortdir=desc&page=1">Date (Oldest to Newst)</a></li>
             <!-- ... -->
        </ul>
    </div>
    The CSS will definitely need some work.
    Last edited by schleppel; 05-08-2014 at 12:00 AM.


  •  

    Posting Permissions

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