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 5 of 5
  1. #1
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,127
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Do I need to set a Default

    I allow users to sort comments as follows...
    PHP Code:
        <!-- Sort Menu -->
        <
    div>
        <
    label for="sortRequest">Sort by:</label>
            <
    select name="sortRequest">
                <
    option value="by-date-asc" >Date (Oldest)</option>
                <
    option value="by-date-desc" >Date (Newest)</option>
                <
    option value="by-most-popular" >Most Popular</option>
            </
    select>                                    
        </
    div

    It appears that when the form is submitted, I am getting the first choice in the dropdown in my $_GET variable.

    This is what I want, but from a coding and security standpoint, should I instead have this...
    PHP Code:
        <!-- Sort Menu -->
        <
    div>
        <
    label for="sortRequest">Sort by:</label>
            <
    select name="sortRequest">
                <
    option value="by-date-asc" selected="selected" >Date (Oldest)</option>
                <
    option value="by-date-desc" >Date (Newest)</option>
                <
    option value="by-most-popular" >Most Popular</option>
            </
    select>                                    
        </
    div
    Sincerely,


    Debbie

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,479
    Thanks
    63
    Thanked 538 Times in 525 Posts
    The default is always the top option. IF you're happy with that there is no need to set it as the selection.
    I can't really think of anything to write here now...

  • #3
    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 tangoforce View Post
    The default is always the top option.
    Right.


    Quote Originally Posted by tangoforce View Post
    IF you're happy with that there is no need to set it as the selection.
    So leaving it that way isn't considered sloppy programming on my part?

    And it shouldn't cause any security issues? (Obviously I sanitize the $GET values.)


    Debbie

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,479
    Thanks
    63
    Thanked 538 Times in 525 Posts
    Not sloppy, no security issues.

    As long as you know what values to expect and are checking them, you're ok.

    The only time you might want to use the selected value is if you want your page to be sticky and remember the users selection.
    I can't really think of anything to write here now...

  • #5
    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 tangoforce View Post
    Not sloppy, no security issues.
    Okay.


    Quote Originally Posted by tangoforce View Post
    As long as you know what values to expect and are checking them, you're ok.
    Always!!


    Quote Originally Posted by tangoforce View Post
    The only time you might want to use the selected value is if you want your page to be sticky and remember the users selection.
    This time I don't really need sticky.

    Sincerely,


    Debbie


  •  

    Posting Permissions

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