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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI form data output problem.... 2

Status
Not open for further replies.

BlckJckFrnk

Technical User
Feb 20, 2002
83
US
Need a little help in getting my output in the order that user inputs it. The user inputs the information in my html form and then I have it e-mailed. However, when the e-mail arrives, the data gets swtiched around and I would like it to arrive in the order of my form. I'm not newbie, but HTML/CGI is something I don't get to do everyday. Thanks

My CGI Program......

$mailprog = '/usr/bin/sendmail';

# change this to your own email address

$recipient = 'Frank@thacherxxxxxxxxx.com';

# this opens an output stream and pipes it directly to the sendmail
# program. If sendmail can't be found, abort nicely by calling the
# dienice subroutine (see below)

open (MAIL, "|$mailprog -t") or &dienice("Can't access $mailprog!\n");

# here we're printing out the header info for the mail message. You must
# specify who it's to, or it won't be delivered:

print MAIL "To: $recipient\n";

# Reply-to can be set to the email address of the sender, assuming you
# have actually defined a field in your form called 'email'.

print MAIL "Reply-to: $FORM{'email'} ($FORM{'name'})\n";

# print out a subject line so you know it's from your form cgi.
# The two \n\n's end the header section of the message. anything
# you print after this point will be part of the body of the mail.

print MAIL "Subject: Form Data\n\n";

# here you're just printing out all the variables and values, just like
# before in the previous script, only the output is to the mail message
# rather than the followup HTML page.

foreach $key (keys(%FORM)) {
print MAIL "$key = $FORM{$key}\n";
}

# when you finish writing to the mail message, be sure to close the
# input stream so it actually gets mailed.

close(MAIL);

# now print something to the HTML page, usually thanking the person
# for filling out the form, and giving them a link back to your homepage

print <<EndHTML;
<h2>Thank you for Contacting us.</h2>
Return to our <a href="/Homepage.htm">home page</a>.
</body></html>
EndHTML

sub dienice {
($errmsg) = @_;
print "<h2>Error</h2>\n";
print "$errmsg<p>\n";
print "</body></html>\n";
exit;
}
 
Code:
foreach $key (keys(%FORM)) {
    print MAIL "$key = $FORM{$key}\n";
}

This is the bit you want

change to something like
Code:
print MAIL "name=$FORM{'name'};
print MAIL "address=$FORM{'address'};
...

HTH
--Paul
 
paul is right when hashes are used they dont keep an order like an array does
 
Thanks for the help. Big help.
However, now I run into a 500 server error, but I 'm sure it's something I've over looked in my script..thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top