Forum Moderators: coopster & phranque

Message Too Old, No Replies

NMS FormMail modification: textarea field output to html page is not like as entered

         

Randal

8:22 pm on Apr 22, 2008 (gmt 0)

10+ Year Member



Hello,
I am using nms formmail.pl script (nms formmail Version 3.14c1) to power a form on my site. When a form is submited, the script outputs an html success page and displays the information entered on the form for review. I've been using this script for a couple years and have tried to figure out on a number of occasion how to make a small change.

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.

phranque

3:14 am on Apr 23, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



something like this might help:
$string =~ s/\n/<br>/g;

perl_diver

4:59 am on Apr 23, 2008 (gmt 0)

10+ Year Member



Another easy fix is to wrap the text in "pre" tags on the html page where it is printed:

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

Randal

2:30 pm on Apr 23, 2008 (gmt 0)

10+ Year Member



Hello phranque,
Thank you for you reply. I have tried before to input a <br> into the script without success. There are a numberous lines of code in the script with a "escape_html". So this morning I basically replaced each one with your code and viola... one worked! The following is the bit that this worked on.

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

perl_diver

6:57 pm on Apr 23, 2008 (gmt 0)

10+ Year Member



You find the code in the perl script that generates the output and apply it there. If you found where to modify the regexp I would think you could find the part of the script that generates the dynamic output since that is generally obvious, but not always.

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.

perl_diver

7:00 pm on Apr 23, 2008 (gmt 0)

10+ Year Member



if $string is the eventual output this might also work:

$string = "<pre>$string</pre>";

you would most likely apply the pre tags as late as possible in the script, just before $string gets printed out to the screen.

Randal

3:03 pm on Apr 24, 2008 (gmt 0)

10+ Year Member



Well this is the code that outputs the html page.... still not sure how to aplly a <pre> tag to that?

<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

perl_diver

7:34 am on Apr 25, 2008 (gmt 0)

10+ Year Member



instead of this:

$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.