in reply to Re: Processing Textarea data
in thread Processing Textarea data

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.

Replies are listed 'Best First'.
Re^3: Processing Textarea data
by atcroft (Abbot) on May 17, 2004 at 16:41 UTC

    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
    TestHTML codeDisplayed
    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.

Re: Re: Re: Processing Textarea data
by eric256 (Parson) on May 17, 2004 at 16:04 UTC

    Actualy he only puts the br after the value. It looks like its printing "Names:" followed by all the names grouped together. Viewing the source would probably show all the names on seperate lines. I think atcroft is quite right here but then we need the OP to be a little more specific about what he _is_ getting.


    ___________
    Eric Hodges