Here's what I am trying to change….
I have a textarea box on the form for people submit text to be engraved. The problem is, the html success page generated by the script does not recognize breaks (carriage returns) used in the textarea field, so everything entered in the textarea box comes out as one continuous line of text. This gets confusing for some of my customers… they think they didn't enter the information correctly. I do have instructions on the form for them to actually designate each , i.e., line 1, line2…etc. But most people don't read the instructions.
If anyone is familiar with this script and can help me with this, I would be most grateful.
Note: The output in the email the the script sends is fine. It displays the text just as it was entered on the form. This problem is only with the html "success" page generated by the script.
<pre>
$text_from_form
</pre>
that retains formatting. You can add style attributes (inline or via a style sheet) to the pre tag to put a border around it or whatever you want to make the display standout a bit or just leave it like that.
<original code>
=item _escape_html_8859_1 ( STRING )
=cut
sub _escape_html_8859_1
{
my ($string) = @_;
$string =~ s¦([^\w \t\r\n\-\.\,\/\:])¦ $eschtml_map{$1} ¦ge;
return $string;
}
</original code>
So I replaced this:
$string =~ s¦([^\w \t\r\n\-\.\,\/\:])¦ $eschtml_map{$1} ¦ge;
with...
$string =~ s/\n/<br>/g;
This works. So with a real lack of knowledge of Perl, my next question is, should I replace the whole line or is there a better way to structure that line. I've tried just inputting the "\<br>\" into the line and that doesn't work but, I really don't understand what all is actually happening in that line of code. So I'm not sure if replacing the whole line is right... even though it works.
Thanks,
Randal
perl_diver - thanks for your input. I've use the <pre> tag in my php scripts but quite uncertian where to apply it in this perl script... The html output page dinamically generated so there is not an html page per say to apply this.
I would not do what you did with the regexp though. Don't replace the line in the script with your new line because there might be good reasons the other line is there and it is doing a number of things not related to simply adding <br> tags where necessary. You can probably add the line below the existing line and see if it works OK.
<code>
=item success_page_fields ()
Outputs success page HTML output for each input field.
=cut
sub success_page_fields {
my ($self) = @_;
foreach my $f (@{ $self->{Field_Order} }) {
my $val = (defined $self->{Form}{$f} ? $self->{Form}{$f} : '');
$self->success_page_field( $self->escape_html($f), $self->escape_html($val) );
}
}
</code>
What I did do though is just add the line "$string =~ s/\n/<br>/g;" like you said and so far it seems to be working just fine.
<code>
=item _escape_html_8859_1 ( STRING )
=cut
sub _escape_html_8859_1
{
my ($string) = @_;
$string =~ s¦([^\w \t\r\n\-\.\,\/\:])¦ $eschtml_map{$1} ¦ge;
$string =~ s/\n/<br>/g;
return $string;
}
</code>
Again, thank you all for you time.
Randal
$string =~ s/\n/<br>/g;
return $string;
you can try:
return "<pre>$string</pre>";
and see how well it works.
Edit: on second thought it will probably add the tags to every field, which will obviously not be good, but maybe just try it and see if you want to.
There must be some place else in the script that prints the final data out, the code you posted is not that part of the script I don't think.