Results 1 to 14 of 14

Thread: Dropdowns

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Arrow Dropdowns

    How do you read and pass the selected option from a dropdown?
    I dont want to use the querystring as I need it in a hidden text field that I can write to a cookie.

    Thanks
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Dropdowns

    What do you want? A hidden field or a drop down? Whatever you want you need to enclose the value in a POST form and give it a name.

    Then access it in the code using:
    Code:
    $_POST['varName'];
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Dropdowns

    On a page I have a couple of dropdowns. When its submitted the selected values need to be transferred to the same page upon reloading and update the selections in the database too.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Dropdowns

    The HTML form element has an action attribute - set this to the name of the PHP script or $_SERVER['PHP_SELF'] in your case. If you give the submit button a name you can then check for this when the form is submitted.

    PHP Code:
    <?php
        
    if (isset($_POST['submit']])) {
           
    // process form here
        
    }
    ?>
    <html>
        <body>
            <form action="<?php echo($_SERVER['PHP_SELF']) ?>" method="post">
                <p><input type="submit" name="submit" /></p>
            </form>
        </body>
    </html>
    I wouldn't recommend submitting to the same page though, as this causes those nasty "would you like to re-submit the data" dialogs when you press the back button.

    The best approach IMO is to have IN and OUT scripts like variable in PLSQL. The OUT scripts produce HTML and the IN scripts process posted form data. So the flow would go as follows:
    Code:
    myform.php ---> POST --> myform_in.php 
       ^                           |
       |                           |
      yes                          |
       |                R          |
       |                E          V
       |----- error <---D-- [process data]
       |                I
       |                R
       no               E 
       |                C
       |                T 
       V
    results.php
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Dropdowns

    I use a If on the same page but everytime a user needs to update a record it should just reload the page to show the update. the form is nested in a per record basis in order to identify which record is being updated.

    The manage is the do parameter of the action element "action=myfile.php?do='manage'"


    Currently doing...
    PHP Code:
    if ($_REQUEST['do'] == 'manage')
    {
        
    //Stuff    

    But if the page needs to remain and let them "manage" it then it seems too many redirects your way?
    Last edited by RobDog888; Jan 24th, 2008 at 06:24 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Dropdowns

    The redirection is almost transparent to the user if you use a Location header. You may also want to consider using caching headers to prevent the dynamic data from being recalled from the browser cache.

    See: http://www.php.net/header
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Dropdowns

    But what about reading the selected value from the dropdown?


    PHP Code:
    <form action="page1.php?do=manage" method="post">
    <
    div>
        <
    select name="ddl1" />
            <
    option value="">&nbsp;</option>
            <
    option value="1">Option1</option>
            <
    option value="2">Option2</option>
            <
    option value="3">Option3</option>
        </
    select>
    </
    div>
    <
    input type="hidden" name="ddl1" value="???" />
    </
    form
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Dropdowns

    Quote Originally Posted by visualAd
    wouldn't recommend submitting to the same page though, as this causes those nasty "would you like to re-submit the data" dialogs when you press the back button.

    The best approach IMO is to have IN and OUT scripts like variable in PLSQL. The OUT scripts produce HTML and the IN scripts process posted form data.
    I do this too. The scripts that handle non-idempotent requests produce 303 redirections to their eventual location (static HTML page, or PHP-generated HTML).

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Dropdowns

    Quote Originally Posted by RobDog888
    But what about reading the selected value from the dropdown?
    $_POST['ddl1'] will contain the selection value: either blank, '1', '2', or '3'.

  10. #10
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Dropdowns

    I am sure I described how to do this earlier

    There is no need for a hidden one if you are auto selecting the blank one.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  11. #11
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Dropdowns

    Quote Originally Posted by visualAd
    The HTML form element has an action attribute - set this to the name of the PHP script or $_SERVER['PHP_SELF'] in your case. If you give the submit button a name you can then check for this when the form is submitted.

    PHP Code:
    <?php
        
    if (isset($_POST['submit']])) {
           
    // process form here
        
    }
    ?>
    <html>
        <body>
            <form action="<?php echo($_SERVER['PHP_SELF']) ?>" method="post">
                <p><input type="submit" name="submit" /></p>
            </form>
        </body>
    </html>
    I wouldn't recommend submitting to the same page though, as this causes those nasty "would you like to re-submit the data" dialogs when you press the back button.

    The best approach IMO is to have IN and OUT scripts like variable in PLSQL. The OUT scripts produce HTML and the IN scripts process posted form data. So the flow would go as follows:
    Code:
    myform.php ---> POST --> myform_in.php 
       ^                           |
       |                           |
      yes                          |
       |                R          |
       |                E          V
       |----- error <---D-- [process data]
       |                I
       |                R
       no               E 
       |                C
       |                T 
       V
    results.php
    If you post to a separate file, and then redirect to the original file, won't you lose the sent data? You can't repopulate the form with the data? (unless you pass it back in the url? ($_GET)).


    Has someone helped you? Then you can Rate their helpful post.

  12. #12
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Dropdowns

    That is correct, this is where sessions will come in handy as you can repopulate the data from the session variables in addition to any error messages you may / may not wish to display.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  13. #13
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Dropdowns

    I suppose that would be one method. And then clearing it so you don't keep populating the form with the most recent data? If the user was to go to the same page again?


    Has someone helped you? Then you can Rate their helpful post.

  14. #14
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Dropdowns

    Yes, I've made a form class to do this all for me.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width