Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a web form to output a CSV file

Status
Not open for further replies.

Coogan

Programmer
Jun 21, 2004
38
GB
Hi Folks,

I am looking at designing a web form that captures data and then emails me the data in a csv file.

1. Is this possible?
2. If it is then are there any good articles on how to do it?

Many thanks.
 
Yes its very possible

Have a look at the FAQ section here, and in the CGI Forum on Tek-tips

faq219-364
faq219-2090

Any problems get back to us
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
save this as an HTML file:-

Code:
<html>
<body>
<form name="form1" method="get" action="[b][URL unfurl="true"]http://perltesting/cgi-bin/csv_email.cgi[/URL][/b]">
  <input type="text" name="textfield">
  <input type="hidden" name="hiddenField" value="hidden data here...">
  <textarea name="textarea"></textarea>
  <input type="checkbox" name="checkbox" value="checkboxValue321">
  <input name="radiobutton" type="radio" value="radiobuttonValue12345">
  <p>
    <label>
    <input name="RadioGroup1" type="radio" value="radioValOption1" checked>
  a</label>
    <br>
    <label>
    <input type="radio" name="RadioGroup1" value="radioValOption2">
  b</label>
  </p>
  <p>
    <input type="submit" name="Submit" value="Submit">
    <br>
  </p>
</form>
</body>
</html>

then run this script:-

Code:
#!/usr/bin/perl

print "Content-type: text/html\n\n";

$ENV{'QUERY_STRING'} =~ s/&Submit=Submit//;
$ENV{'QUERY_STRING'} =~ tr/+/ /;
$ENV{'QUERY_STRING'} =~ s/%(..)/pack("c", hex($1))/eg;

@pairs = split (/&/, $ENV{'QUERY_STRING'});

open (MAIL, '| /usr/sbin/sendmail -t');
print MAIL "To: [b]you\@yourisp.com[/b]\n";
print MAIL "From: [b]you\@yourisp.com[/b]\n";
print MAIL "Subject: CSV e-mail\n";

foreach $pair (@pairs) {
  ($field, $value) = split (/=/, $pair);
  print "<li>$field => $value,";
  print MAIL "$field => $value,";
}


Kind Regards
Duncan
 
Dunc,

your understanding of what needs to be done to accomplish the task is exemplary, but you're giving quick fixes without explanation, which may not encourage the pupil/student/grey oaf||me to learn.

Just a point of view of the grey oaf||me - it's best to show someone how to solve an issue, then give them an issue to solve --or-- answer the question in such a way that it requires the asker to do some research -- the sh!t we know takes learning, over one timescale or another, and just dumping an answer in the lap, doesn't facilitate education, just a short term amelioration of the issue.

It's not a slight at you, give me nod when you've read this, and I'll ask the mods to delete, or feel free to do so yourself

prePS - only trunc this node and down, or else the question won't have been answered at all

Best Regards
--Paul

Meet you for a beer at yapc.eu?


It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Paul

What can I say? You are right. It is pretty stupid of me to respond to a post in this fashion - as you quite rightly point out it wont assist a great deal with anyone learning how to solve problems - as we both did||doing. It's partly that I don't take myself very seriously. I always think someone is going to come up with a much better alternative.

Not thinking very straight at the moment... I'm just starting to try learn sed and awk and i'm simply amazed at the sheer power of these two utilities - and it reminds me that i'm just toying with all this stuff. Taken seriously it looks to me that learning sed alone will take an age. Oh well its all good fun!

Please do remove the 'answer' - I totally agree with your post and will try my best not to do this again. Encouragement, not answers... I get it!

Cheers Paul :)


Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top