Forum Moderators: coopster & phranque

Message Too Old, No Replies

renaming input names for clearer output

how can I rename input names for a clearer email output

         

w9kh

11:23 pm on Feb 17, 2006 (gmt 0)

10+ Year Member



I am using a cgi script called "novice.cgi", which is a very basic script for handling form - to - email.
In the html form I have many different input names (ie. techhaz, hathaz), so when the output is emailed, those words show up as the identifiers with whatever was selected for that particular one. How can I change the output so that instead of showing "techhaz" it would say "Technological Hazard" in the email?

Thank You

pixel_juice

11:25 pm on Feb 17, 2006 (gmt 0)

10+ Year Member



Hi w9kh and welcome to webmasterworld [webmasterworld.com]! :)

The easiest way to accomplish what you want is to simply change the names of the inputs in your form to reflect the text you want to appear in the email you are sent. You would need to ensure that you form processor handles these though, in case is not set up to accept all of the data that is sent from your form.

w9kh

12:15 am on Feb 18, 2006 (gmt 0)

10+ Year Member



Thanks much. I didn't think using a "sentence" instead of just a word to identify an input name would work.

w9kh

1:53 am on Feb 18, 2006 (gmt 0)

10+ Year Member



Ok, didn't quite work the way I hoped it would. Basically is there any way in the cgi program that I can take the inputname and rename it?
inputname=perilinsurance
have the cgi program change it for the email to> "Does this household have open perils insuance".
the longer, easier to understand phrase didn't work well (if at all) when I changed it in the html.
Would some kind of "if then" statement be possible? If inputname=perilinsurance then (whatever the output name is)="Does this household have open perils insurance"
Unfortunately I haven't done much with cgi. I have done more with flash, so cgi is a fairly new arena for me.

Thanks.

lexipixel

5:50 am on Feb 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




"..I have done more with flash, so cgi is a fairly new arena for me.."

The only thing the two have in common are that they are both done on a computer, (perl and flash).

A lot of questions, but since you seem to not know where to look, I'll just give you some clues.

Important Question:

1. Is one single perl script creating the form AND collecting the data AND sending the email?

If so, you can open the file with a text editor and check for the following;

You will need to know if the script processes all value=name pairs in the query string or was written to only handle certain pairs.

It may use the CGI perl module;


#
use CGI;
$query = new CGI;
#
$varname1 = ($query->param("varname1"));
$varname2 = ($query->param("varname2"));
$somelabel = ($query->param("somelabel"));
$person = ($query->param("person"));
$place = ($query->param("place"));
$thing = ($query->param("thing"));
#

or it may use perl native functions to parse out the CGI name=value pairs;


#
if ($ENV{'QUERY_STRING'}) {
$buffer = $ENV{'QUERY_STRING'};
} elsif ($ENV{'CONTENT_LENGTH'}) {
read (STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
}
@cgiPairs = split(/&/,$buffer);
foreach $cgiPair (@cgiPairs) { ($name,$value) = split(/=/,$cgiPair);
$value =~ s/\+/ /g;
}
#

If it is parsing out any pairs regardless of label (name) and value, you can just move ahead to reformatting the data.

If it specifically declares each name=value pair, (using ($query->param("label")), you will need to rework those lines of code to match what you are doing in the (HTML form) INPUT name= markup.

...either way, you will need to handle each name=value pair and reformat the data before it is sent as email.

Somewhere in the script, there is probably some code that looks like:


#
open (MAIL,"¦$mailprog -t") ;
print MAIL "To: $webmaster\nFrom: web_form@domain.tld\n";
print MAIL "Subject: Stuff from form\n";
print MAIL "THIS WAS SENT FROM FORM:\n\n$label1: $var1\n\n$label2: $var2\n\$label3: $var3\n\$label4: $var4\n\$label5: $var5\n\n";
close (MAIL);
#

You would need to reformat the data and replace the line that reads "THIS WAS SENT FROM FORM...".

For instance, you could do:


#
if $label eq 'perilinsur') {
$new_label1 = 'Does property have peril insurance';
}
#

Then use $new_label1 in the print MAIL line...

Hope this helps.

perl_diver

6:10 am on Feb 18, 2006 (gmt 0)

10+ Year Member



syntax correction:

#
if $label eq 'perilinsur') {
$new_label1 = 'Does property have peril insurance';
}
#

should be:

#
if ($label eq 'perilinsur') {
$new_label1 = 'Does property have peril insurance';
}
#

perl_diver

6:13 am on Feb 18, 2006 (gmt 0)

10+ Year Member



post your html form and your script code, but don't post real URL's in your code, use www.example.com or the moderators will just change it for you anyway since posting real URL's is against the posting guidlines.

w9kh

7:10 pm on Feb 21, 2006 (gmt 0)

10+ Year Member



Here is a snippet of the cgi file. The full program is novice.cgi. Below the cgi, I also attached a snippet of the html code so you can see what I am trying to do. I am assuming that I can replace the last print MAIL line with the input names and what text I want it to be instead.
Thanks for all the input and help.

if ($useLib eq "sendmail") {

#############################################
# ABOVE CHECKS WHAT SEND TYPE TO USE #
#############################################

$msgSubject = "Novice Form Submission" . "$POST{'subject'}";

open(MAIL, "¦$mailprog -t") ¦¦ die "Can't open $mailprog!\n";
print MAIL "To: $sendto\n";
if ($ccto){
print MAIL "Cc: $ccto\n";
}
print MAIL "From: $POST{'email'}\n";
print MAIL "Subject: $msgSubject\n";
print MAIL "The form below was submited by $POST{'email'} form Ip address: $ENV{'REMOTE_ADDR'} on $monthnameactual $dayofmonth, $year at $newhour:$newmin\n";
print MAIL "-------------------------------------------------------------------------\n\n";

if (! $POST{'sort'}) {

for ($indexval = 0; $indexval < @formvalue; $indexval++) {
${'myname'} = $formname[$indexval];
${'myvalue'} = $formvalue[$indexval];

if (${'myname'} eq "subject" ¦¦ ${'myname'} eq "required" ¦¦ ${'myname'} eq "sort" ¦¦ ${'myname'} eq "success_page" ¦¦ ${'myname'} eq "ccto" ¦¦ ${'myname'} eq "sendto"){
$dontrun = "1";
}else{
$dontrun = "";
}

if (! $dontrun){
print MAIL "${'myname'}: ${'myvalue'} \n\n";
}
}

}else{ ##ELSE IF NO SORT FIELD ##

for ($numsort = 0; $numsort < @sortfields; $numsort++) {
$sfield = $sortfields[$numsort];
${'sfieldvalue'} = $POST{"$sfield"};
${'sfield'} = "$sfield";

print MAIL "${'sfield'}: ${'sfieldvalue'} \n\n";

}

} ## END ELSE IF SORT FIELD ##

close MAIL;

HTML:

Tornado: <br>
<input name="tordis" value="Extremely Concerned" type="radio">Extremely
Concerned <input name="tordis" value="Very Concerned" type="radio">Very
Concerned <input name="tordis" value="Concerned" type="radio">Concerned
<input name="tordis" value="Somewhat Concerned" type="radio">Somewhat
Concerned <input name="tordis" value="Not Concerned" type="radio">Not
Concerned <br>
<br>
Flood:<br>
<input name="flooddis" value="Extremely Concerned" type="radio">Extremely
Concerned <input name="flooddis" value="Very Concerned" type="radio">Very
Concerned <input name="flooddis" value="Concerned" type="radio">Concerned
<input name="flooddis" value="Somewhat Concerned" type="radio">Somewhat
Concerned <input name="flooddis" value="Not Concerned" type="radio">Not
Concerned <br>
What is the most effective way for you to receive information on how to
make your home safer?<br>
<table style="width: 100%; text-align: left;" border="0"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;"><input name="effectiveinfo"
value="Newspaper" type="radio">Newspaper<br>
</td>
<td style="vertical-align: top;"><input name="effectiveinfo"
value="Television" type="radio">Television<br>
</td>
<td style="vertical-align: top;"><input name="effectiveinfo"
value="Radio" type="radio">Radio<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><input name="effectiveinfo"
value="Mailings" type="radio">Mailings<br>
</td>
<td style="vertical-align: top;"><input name="effectiveinfo"
value="Internet" type="radio">Internet<br>
</td>
<td style="vertical-align: top;"><input name="effectiveinfo"
value="Schools/Universities" type="radio">Schools/Universities<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><input name="effectiveinfo"
value="Outdoor Advertisement" type="radio">Outdoor Advertisement<br>
</td>
<td style="vertical-align: top;"><input name="effectiveinfo"
value="Other" type="radio">Other<br>
</td>
<td style="vertical-align: top;"><br>
</td>
</tr>
</tbody>
</table>
<br>
<br>
Does your household have insurance for open-perils(fire, wind, rain)?<br>
<input name="openperilsinsurance" value="Yes" type="radio">Yes <input
name="openperilsinsurance" value="No" type="radio">No<br>
<br>
If NO, what is the main reason for not having open-peril insurance?<br>
<table style="width: 100%; text-align: left;" border="0"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;"><input name="openperilreason"
value="Too expensive" type="radio">Too Expensive<br>
</td>
<td style="vertical-align: top;"><input name="openperilreason"
value="Not necessary" type="radio">Not Necessary<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><input name="openperilreason"
value="Never considered it" type="radio">Never Considered it<br>
</td>
<td style="vertical-align: top;"><input name="openperilreason"
value="Deductible is too high, not worth it" type="radio">Deductible
is too high, not worth it<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><input name="openperilreason"
value="Not familiar with it" type="radio">Not familiar with it<br>
</td>
<td style="vertical-align: top;"><input name="openperilreason"
value="Other" type="radio">Other<br>
</td>
</tr>
</tbody>
</table>
<br>