Industry guru Dave Taylor answers free tech support questions about a wide variety of business and technical topics, including blogging, Google AdSense, MySpace, Sony PSP, Apple iPod, Mp3 players, management, Linux, SEO, Mac OS X, Facebook, Twitter, LinkedIn and Microsoft Windows.

How do I automatically print the results of an HTML FORM?

Dave, I remember reading your book Creating Cool Web HTML 4 Web Pages and seeing a sample about a sub shop where online customers could order sandwiches...

Can you help me find a script that will take FORM information and upon submit, send it directly to a network printer? This is for a local courier service I am building a site for and I would like to offer them real time, print outs of web based delivery orders.

Dave's Answer:

Hmmm.... I'm not sure that you actually want a form on your Web site that feeds directly to a printer since I would worry that it could be abused and you could end up wasting reams of paper and having a hard time finding the legitimate courier orders in the piles.

An alternative approach would be to have all the requests queue up in some sort of rudimentary database then have a simple review procedure where someone could eyeball each entry and, if they're valid and legit, print them and distribute them as a courier work order.

However, that's not what you asked me, so let me solve the problem you posed. I would create a form that produces a printout by setting up an email address on my server that feeds directly to a printer. For example, "printout@yourhost.com". On a Unix or Linux system, that might well be as simple as adding a line like this to your /etc/aliases file:

printout : "|/bin/lpr"

On a Mac or PC you'd need to get a bit further into scripting to have as neat and elegant a solution.

With that in place, you can use a simple form to email CGI script, of which there are many available and probably one already installed on your Web hosting system. Simply point the script to the printout address and you should be good to go.

If you do use this approach, you'll want to be sure that the HTML form does not include the email address, even as a hidden field. The form shouldn't have any email addresses embedded within it because that information can be much more safely stored in the CGI script itself, away from prying eyes and spammer's email harvesting tools.

I hope this helps you out. Good luck!



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments

Dave, I actually have an additional question to this post. I was wondering if you have happen to try this with an Exchange 2003 server? This is what my company uses as a email server and I was curious if you knew whether or not it did in fact work properly.

Thank you.

Posted by: JeremyB at January 7, 2005 12:10 PM

I haven't worked with Exchange server, but it strikes me that you can probably use ANY email program and just create a special ruleset that matches these incoming messages and automatically prints them to the local printer. You'd need to leave the computer running and the mail program grabbing email every so often, but I think that might be the easiest of all solutions, actually. No custom CGI work involved, and no monkeying with the sendmail aliases file either.

Posted by: Dave Taylor at January 7, 2005 7:49 PM

In this page when you place the mouse over the underlined words a small window appears, can u please tell me how to do that

I shall eagerly be waiting for your email

Thanking you in advance
Shriram

Posted by: Shriram at February 13, 2007 4:48 AM

Shiram, the specific system I have here is the Kontera advertising network, but generally, it's just a CSS layer that's transparent until you "onMouseOver" the link. Complicated, but not terribly so...

Posted by: Dave Taylor at February 13, 2007 9:35 AM

Hi Dave

We need to generate a web page that will print to a local printer automatically when the user clicks on a "Print" link on our page. To put it another way, we'd like to automate the user interaction associated with the print dialogue. If necessary, we could create a small .exe file installed on the client computer. Any thoughts?

Thanks,
Dan

Posted by: Dan at October 10, 2007 10:03 AM

I have a lot to say, but ...
Starbucks coffee cup I have a lot to say, and questions of my own for that matter, but most of all I'd like to say thank you for all your efforts on this Web site by buying you a chai!

I do have a comment, now that you mention it!









Remember personal info?


Please note that I will never send you any unsolicited commercial email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Join the List!
Join my author info mailing list, where you'll learn about my upcoming books, speaking gigs, and more!


Book Links
© 2002 - 2008 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]