How pass a variable from a form to a subroutine
Posted by ability (ability), 28 October 2002I'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">
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 2002I'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:
and then in my main code (to answer your question) I would write
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 2002I'm a big fan of CGI.pm, and its simple to use too.
what if your html select box allowed multiple selections?
Posted by John_Moylan (jfp), 29 October 2002Oh, 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.
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: email@example.com • WEB: http://www.wellho.net • SKYPE: wellho