PDA

View Full Version : HTML Question



Dayspring
08-16-2004, 10:38 AM
I'm working on a project at the office and I need to take all sorts of form data and have it output that as an HTML file somewhere on the site. (Each time the form is activated, I want it to generate a new HTML file.)

Ideas?

InexactMelissa
08-16-2004, 11:23 AM
Many, many ways you can do that depending on the application and available scripting languages....But if you don't want to store the data collected from the form on a database, probably to most basic way is by using a document.write command in javascript.

Here's an example:

http://www.mediacollege.com/internet/javascript/basic/document-write.html

Dayspring
08-16-2004, 11:41 AM
We'd rather not use a database. The boss wants the forms to dump their output into an HTML file (Per submission), almost like a receipt of sorts.

I'm going to look into the document.write command and see if it has parameters to do an HTML file, not just to the screen.

Dryden
08-16-2004, 12:37 PM
Seems to me the easiest (and most secure) route would be to use PHP, but an alternative quick and dirty way to do it would be to use the venerable, free/GPL'ed formmail.cgi script from the old Matt's Script Archive and use an e-mail template in the form of HTML that's piped to a directory instead of Sendmail.

Do you have any code to work with now, or are you building from scratch? Does the output need to be archived/searchable? What type of data are you storing and do you need to do calculations against it?

InexactMelissa
08-16-2004, 12:43 PM
So you're just going to have an html file created and saved every time this form is submitted? It seems like that could pose some security issues as well as cluttering up your server.

Dayspring
08-16-2004, 12:53 PM
Basically, this is just a work order form for a few procedures done in the office. We wanted a way to do it online to eliminate the paper. I'm pretty much doing it from scratch, I have the forms done and use the formmail.cgi to output it as an email. If there's a way to output it to a file, I'd appreciate a little help on that.

It doesn't need to be searchable or anything fancy. We just want a file stored in a directory that's time stamped (or by user submitted address) as a "CYA" measure of "yes we received your email and have a file to prove that you submitted it."

Security wise, it's an internal form, used by about 20-30 total people.


Seems to me the easiest (and most secure) route would be to use PHP, but an alternative quick and dirty way to do it would be to use the venerable, free/GPL'ed formmail.cgi script from the old Matt's Script Archive and use an e-mail template in the form of HTML that's piped to a directory instead of Sendmail.

Do you have any code to work with now, or are you building from scratch? Does the output need to be archived/searchable? What type of data are you storing and do you need to do calculations against it?

Dryden
08-16-2004, 01:03 PM
Are you running Unix or Linux? If so, you could pipe the e-mail into a file by placing a .forward file in a user's home directory with the contents of "/var/www/html/<somefile>"

I'd have to play around with the syntax for a little bit to figure it out, but you should be able to use shell escapes in the .forward file to write multiple, single time-stamped files as the name of <somefile>

Dayspring
08-16-2004, 01:16 PM
Sadly, I have no idea what kind of system they are running. I'm going to GUESS and say UNIX. The only reason I am trying to stay away from PHP is that I don't think they're running it. Here's the code string I'm running right now to email the results out.



form method="post" action="http://**.**.com/divisions/esm/cgi-bin/formmail/formmail.cgi"
input type="hidden" name="recipient" value="****@**.com" /
input type="hidden" name="subject" value="ESM Work Order" /

Dryden
08-16-2004, 01:45 PM
This sounds like a similar setup I use here for automated ordering systems, and since you're using formmail.cgi I'd imagine you're running some variation of *nix w/ Sendmail.

What I do for this is use the forwarding mechanism in the mail server to fork the e-mail from formmail and deliver one copy to the order processing department and one copy to a dump file on the server for archiving.

For example, I want an employee, jdoe@mycompany.com, to receive the order via e-mail while storing a duplicate to disk in the event John Doe deletes his mailbox, crashes his computer, etc. I can't mirror John Doe's mailbox though because I'd also be duplicating all his other mail, so what I do instead is route the formmail.cgi script to a phony account that forks the message to two destinations.


1. Create a new user account on the mail server, named something relevent to the application.
2. In the home directory for this new user, create a new file named .forward
3. In the .forward file, add the following two lines:

jdoe@mycompany.com
/<path>/orders

4. Edit the hidden recipient field in the .html form to use this new dummy account

What happens is formmail.cgi processes the e-mail as normal and passes the message to Sendmail. Sendmail receives the message and does a lookup in the home directory of the recipient for special handling instructions. If the user has a .forward file, Sendmail delivers to those recipients instead. Since one of the recipients listed is the path to a text file, sendmail will append the message to that file like it would with any regular flat-text file POP mailbox - but in this case it's not actually a mailbox, it's a dump file that nobody ever reads.

You could browse this file just like a mailbox file later, archive it, or process it further with a different CGI script. Another feature in most any *nix based mail server will be a mail handling agent named Procmail, which could be used to randomize the file name to write several individual files into a directory - one for each order.

Dayspring
08-16-2004, 02:11 PM
I'll look into it, but getting a fake email address is going to be nigh impossible...

There any way of getting around that or am I going to have to go to our designer and get him to do a nifty perlscript thing?

Thank you for your help so far though. It's given me some good ideas.


This sounds like a similar setup I use here for automated ordering systems, and since you're using formmail.cgi I'd imagine you're running some variation of *nix w/ Sendmail.

What I do for this is use the forwarding mechanism in the mail server to fork the e-mail from formmail and deliver one copy to the order processing department and one copy to a dump file on the server for archiving.

For example, I want an employee, jdoe@mycompany.com, to receive the order via e-mail while storing a duplicate to disk in the event John Doe deletes his mailbox, crashes his computer, etc. I can't mirror John Doe's mailbox though because I'd also be duplicating all his other mail, so what I do instead is route the formmail.cgi script to a phony account that forks the message to two destinations.


1. Create a new user account on the mail server, named something relevent to the application.
2. In the home directory for this new user, create a new file named .forward
3. In the .forward file, add the following two lines:

jdoe@mycompany.com
/<path>/orders

4. Edit the hidden recipient field in the .html form to use this new dummy account

What happens is formmail.cgi processes the e-mail as normal and passes the message to Sendmail. Sendmail receives the message and does a lookup in the home directory of the recipient for special handling instructions. If the user has a .forward file, Sendmail delivers to those recipients instead. Since one of the recipients listed is the path to a text file, sendmail will append the message to that file like it would with any regular flat-text file POP mailbox - but in this case it's not actually a mailbox, it's a dump file that nobody ever reads.

You could browse this file just like a mailbox file later, archive it, or process it further with a different CGI script. Another feature in most any *nix based mail server will be a mail handling agent named Procmail, which could be used to randomize the file name to write several individual files into a directory - one for each order.

Dryden
08-16-2004, 02:26 PM
Well, if you can't create a new account to handle the forwarding you could use an existing account that includes itself in the .forward. The problem with this method though is that it would now duplicate everything the user receives to the archive, which probably isn't workable if it's a "real" account that a person is sending mail from (and probably receiving spam to).

I'll see if I can come up with something else in CGI/HTML so you can try to get this as self-sufficient as possible. I've got 10 years worth of old .CGI scripts to look through for ideas (though I must admit the code I wrote when I was 19 wasn't nearly ready for prime-time. :D)

InexactMelissa
08-16-2004, 06:05 PM
I don't know if it will help or not, but here's a tutorial on the Javascript FileSystemObject object: http://www.webreference.com/js/column71/index.html

You may run into some problems with write permissions even if you find a suitable pl script, and I assume that will be a difficult issue to overcome if it is that hard to get an email account out of your company. (it takes a couple of weeks and a committee review for stuff to get moved from UAT to production where I work)

Personally, I would use PHP and a database, but then again, that's what I get paid for :)