Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Formatting Input

by Anonymous Monk
on Jun 14, 2012 at 15:33 UTC ( [id://976234]=note: print w/replies, xml ) Need Help??


in reply to Formatting Input

How can i prevent these blank lines between sentances or paragraphs from being removed?

The only way they get removed is if some code you wrote (or call) removes them -- the solution is to not do that

Without specific code we can't help you, see How do I post a question effectively?

Replies are listed 'Best First'.
Re^2: Formatting Input
by Fletch (Bishop) on Jun 14, 2012 at 15:41 UTC

    Nah, the problem's on line 17. Bleedin' obvious.

    (Yeah, what he said. See also How (Not) To Ask A Question)

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re^2: Formatting Input
by akwe-xavante (Acolyte) on Jun 14, 2012 at 16:02 UTC

    My Perl / cgi script gets data from the webform in this way

    The script gets data from a webform then prints back to the browser, creates a PDF Document and sends an email with the PDF document as an attachment

    The script is long so i've only printed what i think you'l need here - i hope

    #!/usr/bin/perl use strict; use CGI ':standard'; use PDF::API2; use MIME::Lite; use utf8; $Name = param('name'); $Email = param('email'); $Subject = param('subject'); $Contents = param('contents');

    If the users data entered into the variable $Contents contains spaces between lines or paragraphs, these blank lines are removed somewhere during the process of printing it back to the browsers screen and into a PDF Document and the email

    Simplistically its printed back to the browser:

    print "Content-Type:text/html\n\n"; <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.or +g/TR/xhtml11/DTD/xhtml11.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\"> <head></head> <body> <p>Thank you $Name for your message entitled $Subject</p> <br> <p>Your Message was:</p> <br /> <p>$Contents</p> <br /> <p>I will contact you as soon as possible if a response is required.</ +p> <br /> <h2>$MyName</h2> <br /> <br /> <br /> </body </html>

    And Printed into the PDF Document:

    $txt->font($fnt, 8); $txt->translate(25,740); $txt->fillcolor('black'); $txt->text("$Contents");

    And added to an email:

    my $Message = " <p>Thank you $Name for your email.</p> <p>Subject: $Subject</p> <p>Your Message was:</p> <p>$Contents</p> "; my $msg = MIME::Lite->new ( From => $From, To => $To, Subject => "Subject: re: $Subject", Type =>'multipart/mixed' ) or die "Error creating multipart container: $!\n"; ###### Add the text message part # $msg->attach ( Type => 'HTML', Data => "$Message", ) or die "Error adding the text message part: $!\n"; ##### Send the Message $msg->send;
      The problem is that you don't know how HTML works. Consecutive whitespace, such as your line breaks, is collapsed into a single space for display purposes.

      That means before you print your variable contents in HTML, you need to prepare it appropriately. For example, you could wrap whole paragraphs of text into a <p>…</p> element.

        As far as i can see it is when written back to the browser and into the email. It isn't when printed to the PDF Document though

        <p>$Contents</p>
      Nice snippets... but they show nothing that removes common whitespace chars (\s\t\r\n).

      So, in a case of the blind (perhaps mis-) leading the blind, you might want to look at your cgi again, for something like one of these WAGs:

      •   chomp...
      •   s/\./\s$/\./; or s/\n/ /;
        or
      • a regex ending in /s or /m

      This may not help, but it might rule out a few more possibilities.

      Update: Should have said earlier that the initial reply encapsulates the approach to a solution. + +. But also, I read, only after posting the initial version of this node, daxim's node re collapsing of white space and OP's reply, which, though ambiguous, may cast the issue in a different light.

        Thank you for your reply, not added anything to remove whitespace, wouldn't know how to

        If i have then i have done so as a typo somewhere by accident

        Someone is suggesting the problem is on line 17 but i can't find a line 17 that makes any sense no matter how i count down the number of lines, so i don't know which line of code the person is referring to!

    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://976234]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-24 05:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found