Please advise how I can handle Textarea that is coming from form entries where if sometone types in an entry and hits enter to enter new data it would show up on different lines on my action page.
For example in my Textbox with a field called city:
The user would enter several cities in the form textarea like this:
San Francisco
San Diego
Denver
My form would then process this and show on my action page as:
San Francisco San Diego Denver
I want it to show with newlines on my action page just as it was entered in the textbox:
San Francisco
San Diego
Denver
Here is my attempt:
For example in my Textbox with a field called city:
The user would enter several cities in the form textarea like this:
San Francisco
San Diego
Denver
My form would then process this and show on my action page as:
San Francisco San Diego Denver
I want it to show with newlines on my action page just as it was entered in the textbox:
San Francisco
San Diego
Denver
Here is my attempt:
Code:
#!/usr/local/bin/perl -w
#use strict, warnings, web cgi, and browser error modules
use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
my $fetch_data = '';
my ($field, $value);
foreach $field (param)
{
#added this loop to cover multivalued form fields to
#process each value individually if needed
foreach $value (param($field))
{
if($field !~ /city/) #process other fields normally
{
$fetch_data .= "<tr><td>$field:</td><td>$value</td></tr>\n";
}
elsif($field =~ /city/) #process textarea field
{
$textareaField .= "City\:\t$value\n\n<br\>";
}
}
}
print header, <<"EOF";
<HTML>
<BODY>
<table>
$fetch_data
$textareaField
</table>
</HTML>
EOF