|
-
Jan 23rd, 2008, 08:02 PM
#1
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 24th, 2008, 07:45 AM
#2
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:
-
Jan 24th, 2008, 12:08 PM
#3
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 24th, 2008, 12:43 PM
#4
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
-
Jan 24th, 2008, 01:50 PM
#5
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 24th, 2008, 08:08 PM
#6
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
-
Jan 24th, 2008, 09:39 PM
#7
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=""> </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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 25th, 2008, 01:54 AM
#8
Re: Dropdowns
 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).
-
Jan 25th, 2008, 01:55 AM
#9
Re: Dropdowns
 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'.
-
Jan 25th, 2008, 04:11 AM
#10
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.
-
Feb 15th, 2008, 09:19 AM
#11
Re: Dropdowns
 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. 
-
Feb 15th, 2008, 10:48 AM
#12
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.
-
Feb 15th, 2008, 12:00 PM
#13
-
Feb 15th, 2008, 01:25 PM
#14
Re: Dropdowns
Yes, I've made a form class to do this all for me.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|