Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't print values for a list/menu 1

Status
Not open for further replies.

godzuki

Programmer
Apr 18, 2002
46
GB
hi, my problem is that i am trying to send a form to an email address using perl script to send it on. everything works except the menu/list box on the form which has a the name 'info'. how do i get the perl script to send on values from a menu/list box.....an example of the script is as follows.

print MAIL "Personal Information\n";
print MAIL "Name: $in{'name'}\n";
print MAIL "Address 1: $in{'address1'}\n";
print MAIL "Address 2: $in{'address2'}\n";
print MAIL "Town/City: $in{'towncity'}\n";
print MAIL "Post Code: $in{'postcode'}\n";
print MAIL "Country: $in{'country'}\n\n";

print MAIL "Contact Information\n";
print MAIL "Email: $in{'email'}\n";
print MAIL "Tel: $in{'tel'}\n";
print MAIL "Fax: $in{'fax'}\n\n";

print MAIL "I would like information on $in{'info'} Products please\n\n";

print MAIL "Info: $in{'info'}\n\n"; ** sends nothing ***

the menu/list code is as follows:

<select name="Info" multiple size="5">
<option>Rail Products</option>
<option>---------------------</option>
<option value="Head/Tail/Marker Light - 265X Series">Head/Tail/Marker
Light - 265X Series</option>
<option value="Combined Headlight &amp; LED Tail Light">Combined
Headlight &amp; LED Tail Light</option>
<option value="LED Tail Light Retrofit">LED Tail Light Retrofit</option>
<option value="H.I.D. Headlight - 2610 Series">H.I.D. Headlight
- 2610 Series</option>
</select>

thanks
 
try changing:-

print MAIL "Info: $in{'info'}\n\n"; ** sends nothing ***

to:-

print MAIL "Info: $in{'[red]I[/red]nfo'}\n\n"; ** sends nothing ***


Kind Regards
Duncan
 
Brilliant, it worked!!! thanks for that, your a star? any ideas how i can seperate the list values on seperate lines..

i this result back as it is:-

I would like information on Head/Tail/Marker Light - 265X SeriesCombined Headlight & LED Tail LightLED Tail Light RetrofitH.I.D. Headlight - 2610 SeriesLED Outline Marker Lights - 360 SeriesLED Indicator Lights - 362 SeriesLED Monitor Unit - 373M SeriesGuarded General Purpose Lights 57X/58X Series Products please

thanks
 
Using the info you posted, the following code will work. However, to be safer, you might want to put some unique character at the beginning or end of each item desciription, then substitute that for a new line character.

Code:
my $str = 'I would like information on Head/Tail/Marker Light - 265X SeriesCombined Headlight & LED Tail LightLED Tail Light RetrofitH.I.D. Headlight - 2610 SeriesLED Outline Marker Lights - 360 SeriesLED Indicator Lights - 362 SeriesLED Monitor Unit - 373M SeriesGuarded General Purpose Lights 57X/58X Series Products please';

$str =~ s/( on|Series|Retrofit)\s*(\w+)/$1\n$2/ig;
print $str;
 
hi thanks for your reply, but $str would not necessarily contain all those value's. it would only contain those values selected in the original menu/list...????
 
godzuki,

Use the CGI module by mix-master Lincoln Stein. It is the gold standard for CGI scripts not running under mod_perl

Here is your script... converted (but not tested):
Code:
use CGI;  # this would go somewhere near the top, in your code.
my $q = new CGI;

print MAIL "Personal Information\n";
print MAIL "Name: ", $q->param('name'), "\n";
print MAIL "Address 1: ", $q->param('address1'), "\n";
print MAIL "Address 2: ", $q->param('address2'), "\n";
print MAIL "Town/City: ", $q->param('towncity'), "\n";
print MAIL "Post Code: ", $q->param('postcode'), "\n";
print MAIL "Country: ", $q->param('country'), "\n\n";

print MAIL "Contact Information\n";
print MAIL "Email: ", $q->param('email'), "\n";
print MAIL "Tel: ", $q->param('tel'), "\n";
print MAIL "Fax: ", $q->param('fax'), "\n\n";

print MAIL "I would like information on ", $q->param('info'), " Products please\n\n";

print MAIL "Info: \n";
print MAIL "$_\n" for $q->param('Info');
print MAIL "\n\n";

--jim
 
godzuki, you're absolutely correct. It would just have the selected options - I think I was too vague. My html is a bit rusty but in your option list, for each option, you can have something like:

Code:
<option value="LED Indicator Lights - 362 Series">LED Indicator Lights - 362 Series</option>

And so on... if you added a character or two in your value property, something like:

Code:
<option value="[b][blue]--[/blue][/b]LED Indicator Lights - 362 Series">LED Indicator Lights - 362 Series</option>

It would be much easier to separate the individual items with a regex.
 
Code:
#!/usr/bin/perl

$str = 'I would like information on Head/Tail/Marker Light - 265X SeriesCombined Headlight & LED Tail LightLED Tail Light RetrofitH.I.D. Headlight - 2610 SeriesLED Outline Marker Lights - 360 SeriesLED Indicator Lights - 362 SeriesLED Monitor Unit - 373M SeriesGuarded General Purpose Lights 57X/58X Series Products please';

$str =~ s/([a-z])([A-Z])/$1~$2/g;

@items = split ("~", $str);

print join ("\n", @items);


Kind Regards
Duncan
 
WAKE UP PEOPLE! Trying to parse the items out with a regex is a hack! they are individual items, and can be accessed as such!

If you want to do it the wrong way, then splitting w/ a regex is the way to go. Care about your code working reliably? Use modules that people smarter than all of us have put together.

--jim
 
big thanks all you guys for your replies, i think i'm more confused!!!...not really...

Coderifous can you explain the my $q = new CGI variable and what does it do prefixed before a parameter?
 
dear godzuki,

This is an instantiation ("creation") of an object. The object is of the class CGI. Once you have this object, you can use it to access it's properties and methods (variables and subroutines in perl).

I like using the CGI module via it's Object Oriented interface. It sounds like you are new to perl, and perhaps programming in general. There are many books that could help you out.

please read "perldoc perlboot" for an intro to Perl OO programming.

please read "perldoc CGI" for instructions on how to use the CGI module.

"perldoc" refers to the built-in documentation that comes with most perl modules. At your command line, you can view this documentation by typing "perldoc <module_name_here>"

--jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top