Forum Moderators: open

Message Too Old, No Replies

Printing the contents of a PHP variable

Using Javascript to print a PHP variable

         

user404

8:07 pm on May 17, 2006 (gmt 0)

10+ Year Member



I have built a message I'm sending to the customer (through PHP using mailto): $message. I want a hard copy of this message.

The process that comes to mind is:
1. In PHP addslashes to prepare special symbols.
2. Write a Javascript code, define a new var and post $message to it (VAR mymsg = '<?php echo $message;?>')
3. open a new window that points to a simple html form textarea.
4. Use Javascript to change the value of my textarea to the Javascript variable defined in my other window.
5. Use Window.Print to print it out.
6. Close the new window.

Is there an easier way? Can I do it without opening a new window?

Thanks in advance,

Dave

whoisgregg

11:59 am on May 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Won't that end up printing it out of the visitor's computer?

Are you storing the information in a database already? If not, you could first write the message into a DB, then send it, then create a page that only you access that just brings up the messages one at a time for you to print.

proper_bo

12:35 pm on May 18, 2006 (gmt 0)

10+ Year Member



Won't that end up printing it out of the visitor's computer?

Yes it will.

What exactly are you trying to do?
Do YOU want a copy of the message on paper?
What would you want that when it is you send the message in the first place?

Do you want the users computer to automatically print out the message?
To do that you will indeed need a new window otherwise you will get all the other pages content printing too.
You could use javascript to close the window after though.

user404

1:56 am on May 19, 2006 (gmt 0)

10+ Year Member



I'm emailing people information and I use a PHP script to create the message and send it. I want a hard copy of the message I'm sending out for my records. Now I could send another copy of the email to myself and print out the message from my mail program... but I'm trying to avoid that extra step. After I create the message I'm sending out (which is stored in $message (a PHP variable)) I want to print a copy of the message I sent out on my local printer.

-- Dave

user404

2:32 am on May 19, 2006 (gmt 0)

10+ Year Member



Are you storing the information in a database already? If not, you could first write the message into a DB, then send it, then create a page that only you access that just brings up the messages one at a time for you to print.

I hadn't thought about using a db, but I could write $message to a sql table, use javascript to open a new PHP page which reads the db to get the msg and just prints it as straight html (or put it in a <textarea> block which may cut down on formatting issues). Then all I'd have to do is a window.print() once the page has finished loading...

Someting like <body onLoad="Window.Print()">

I ought to be able to do that. Great idea! Thanks!

How would I close the window and return focus to my original document (my email creator/sender)?

-- Dave