Re: Processing Textarea data
by EvdB (Deacon) on May 17, 2004 at 15:05 UTC
|
from: foreach my $value (param($field))
to: foreach my $value ( split /\n/, param($field) )
You need to take the scalar value that you get from param and turn it into an array.
--tidiness is the memory loss of environmental mnemonics
| [reply] [d/l] [select] |
Re: Processing Textarea data
by atcroft (Abbot) on May 17, 2004 at 15:10 UTC
|
My first guess is that your email is plain text-correct? In HTML, carriage returns in the source are not displayed (unless within <pre></pre> tags). So, I see two possibilities (at least):
- in the section where you display the results, place a set of <pre> tags around $name, or
- after sending the email, but before displaying the results, do a search and replace on \n with <br />\n.
For my part, I would try the first one (as it would be the easier of the two).
Hope that helps.
| [reply] |
|
Tricky question, eh? I think this is a wrong answer, see, the poster already adds <BR /> so that the newlines show up in the html.
I almost got fooled with this one too.
Update:
Sorry, atcroft, this post was a bit too harsh (or cheeky).
I'm now not so sure if param
really returns an array or a scalar here.
I'd still guess scalar, because anonymonk says in the question
The emails come back with names seperated by
CR
Note also that in ruby, for on a string
iterates through its lines (as defined by $/, the
record separator); which may be the source of confusion.
Anyway, adding a <PRE> is a good solution
in either case.
| [reply] [d/l] [select] |
|
Actually, given that the email displays them as the OP desires, but that he wants the results to show up on the web page in the same manner, <pre></pre> tags around the variable will in fact take care of the issue, without having to worry about looking at the parameter in question as a scalar or array.
Test results, result display section, CGI based on OP's provided code |
Test | HTML code | Displayed |
Sample results, original code |
<html>
<body>
Names here: duh<br />Names here: joe
bob
mary<br />
</body>
</html>
|
Names here: duh Names here: joe
bob
mary
|
Sample results, <pre></pre> tags around $name |
<html>
<body>
<pre>
Names here: duh<br />Names here: joe
bob
mary<br />
</pre>
</body>
</html>
|
Names here: duh Names here: joe
bob
mary
|
HTML code, for reference:
<html>
<head>
</head>
<body>
<form action="/cgi-bin/testdump.pl" method=post>
<table>
<tr><td>Department</td>
<td><input type=text name=department></td>
</tr>
<tr>
<td colspan=2>People</td>
</tr>
<tr>
<td colspan=2>
<textarea name=people rows=5 cols=40></textarea>
</td>
</tr>
<tr>
<td><input type=submit></td>
<td><input type=reset></td>
</tr>
</table>
</form>
</body>
</html>
perl code, for reference:
#!/usr/bin/perl
use CGI qw/:standard/;
$| = 1;
foreach my $field (param)
{
foreach my $value (param($field))
{
$name .= "Names here\:\t$value<br />";
}
}
# Mailer section removed from OP's code for testing
print header, <<EOF;
<HTML>
<BODY>
<pre>
$name
</pre>
</BODY>
</HTML>
EOF
Hope that helps. | [reply] [d/l] [select] |
|
| [reply] |
Re: Processing Textarea data
by particle (Vicar) on May 17, 2004 at 15:04 UTC
|
you need to put in a newline, if you want it to appear...
$name .= "Names here\:\t$value<br />\n";
## ^^
| [reply] [d/l] |
Re: Processing Textarea data
by EdwardG (Vicar) on May 17, 2004 at 15:13 UTC
|
One of the advantages of the Web is that text is automatically wrapped into lines fitting within the current window size. Sometimes though, you will want to disable this behavior. For example when including samples of program code.
From http://www.w3.org/MarkUp/Guide/Advanced.html
| [reply] |
Re: Processing Textarea data
by ambrus (Abbot) on May 17, 2004 at 15:15 UTC
|
foreach my $value (param($field))
This loop won't iterate on the lines of the cgi parameter.
param($field) will return only one value, so
the loop body is ran only once.
| [reply] [d/l] [select] |
|
of course param($field) returns all values
belonging to $field, so the loop will iterate over them.
i think you're forgetting multivalued parameters...
| [reply] [d/l] |
|
Yes - in the case of multivalued parameters param will return an array, but in this example the OP is spcifically reffering to a textarea field which results in a scalar.
--tidiness is the memory loss of environmental mnemonics
| [reply] [d/l] |