Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Formatting Input

by Anonymous Monk
on Jun 14, 2012 at 15:33 UTC ( #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?


Comment on Re: Formatting Input
Re^2: Formatting Input
by Fletch (Chancellor) 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 (Novice) 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;

      Thank you for your answer! doesn't really help though

      Line 17 is a blank line!

      Sometimes you just do not know what the question is to get the answer your looking for, i've obviously asked the wrong question or assumed my problem is a formatting issue, i don't know

      I'm still no wiser, smart arse!

      But thank you though, i'm assuming you think that i know what i'm doing - I don't!

        Hoping for a much more helpful answer

        Perhaps i need a better idea about what my problem is so that i can look and find an answer

      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!

      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>

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2014-12-28 04:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (178 votes), past polls