| ||||||||||||||
| ||||||||||||||
How pass a variable from a form to a subroutine Posted by ability (ability), 28 October 2002 I'm new at this but I have a variable, lets call it $var1 and I need a form to pass $var1 to a subroutine in a script.The form has a drop down menu ie <select size="1" name="var1"> <option value="1">1</option> <option value="2">2</option> </select> How do I pass what ever value the user selects from the dropdown menu so that $var1= whatever the drop down menu value is?? Posted by admin (Graham Ellis), 29 October 2002 I'll assume you're using "CGI" - the common gateway interface. If so, you might like to use a module such as CGI.pm to collect all the values from your form using the param method; personally, if this is the only thing that I would be doing with CGI.pm in an application, I just add in my own collect_form subroutine:Code:
and then in my main code (to answer your question) I would write Code:
CGI / getting values from form is a huge subject, but this example is a good general case that picks up all the elements from a form if you've used the GET or POST method when setting up the form. I have an enhanced version that feeds cookie variables and environment variables into the same hash as well to avoid the need to keep recoding. After all, what are subs for? Posted by John_Moylan (jfp), 29 October 2002 I'm a big fan of CGI.pm, and its simple to use too.Code:
what if your html select box allowed multiple selections? Code:
jfp. Posted by John_Moylan (jfp), 29 October 2002 Oh, on a related note.......Don't trust input from users, they mess with things you know. Get used to using the -T switch in your cgi progs, it makes you 'untaint' user input. I'll leave it to you to read up on it. jfp This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
edit your own (not yet published) comments Average page ranking - 5.0 |
| |||||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |