Formatting eMail sent via post

I have two files: estimator.php and thanyou.php

“estimator” is used to caluculate a project estimate via checkbox inputs, “thankyou” sends a note back to me.

Given the way “estimator” works the input tags have identicle name tags so that, the email “thankyou” sends does not have each checkbox specifially called out (thus I get the totals only). I would like to see exaclty which checkboxes got checked also.

Is it possible to create a title tag for each input and have “thankyou” return that title tag?

Here is the sample code which is a subset of the total form.

Thanks.

estimator.php

<html>
<head>
<script type="text/javascript">

function calculate(f)
{ 
var nums = f.num;
var ntext = f.numtext;
var res = 0;
var items = '';
for(var i=0;i<nums.length;i++)
{
if(nums[i].checked)
{
res+=parseFloat(ntext[i].value);
}
}
f.answer.value=Number(res).toFixed(2);
}

function calculate1(f1)
{ 
var nums1 = f1.num1;
var ntext1 = f1.numtext1;
var test = 0;
var items1 = '';
for(var j=0;j<nums1.length;j++)
{
if(nums1[j].checked)
{
test+=parseFloat(ntext1[j].value);
}
}
f1.answer1.value=Number(test).toFixed(2);
}
function area(form) {
a=eval(form.answer.value)
b=eval(form.answer1.value)
{
if(b==undefined)
{
form.silver.value = a
form.gold.value = a*(1.3333333333333333333333333333333333333333)
form.platinum.value = a*(1.6666666666666666666666666666666666666666)

}
else
{

form.silver.value = a+b
form.gold.value = a*(1.3333333333333333333333333333333333333333)+b
form.platinum.value = a*(1.6666666666666666666666666666666666666666)+b
form.test.value = b
}
}
}



</script>
</head>
<body>
<form action="thankyou.php" method="post">
Living<input type="checkbox" name="num" onclick="calculate(this.form)"><input type="hidden" name="numtext" value="30" onchange="calculate(this.form)"><br>
Dining<input type="checkbox" name="num" onclick="calculate(this.form)"><input type="hidden" name="numtext" value="15" onchange="calculate(this.form)"><br>
No Protectant<input type="checkbox" name="num1" onclick="calculate1(this.form)"><input type="hidden" name="numtext1" value="0" onchange="calculate1(this.form)"><br>
Living Protectant<input type="checkbox" name="num1" onclick="calculate1(this.form)"><input type="hidden" name="numtext1" value="15" onchange="calculate1(this.form)"><br>
Dining Protectant<input type="checkbox" name="num1" onclick="calculate1(this.form)"><input type="hidden" name="numtext1" value="15" onchange="calculate1(this.form)"><br>
<p align="center">
 <input name="answer" size="5">
 <input name="answer1" size="5">
 <input name="test" size="5">
 </p><br> 
<p align="center">
<input style="WIDTH: 66px; HEIGHT: 24px" onclick="area(this.form)" type="button" size="6" value="Calculate"><br><input type="reset" value="Reset" name="" object=""></p>
<p align="center">silver<input size="4" name="silver" number="silver"></p></td><!-- Col 1 -->
<p align="center">gold<input size="4" name="gold" number="gold"></p></td><!-- Col 2 -->
<p align="center">plat<input size="4" name="platinum" number="platinum"></p>
</form>
</body>
</html>

thankyou.php

<?php
if ($_SERVER['REQUEST_METHOD']=="POST"){
// In testing, if you get an Bad referer error
// comment out or remove the next three lines
if (strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'])>7 ||
!strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']))
die("Bad referer");
$msg="Values submitted by the user:n";
foreach($_POST as $key => $val){
if (is_array($val)){
$msg.="Item: $keyn";
foreach($val as $v){
$v = stripslashes($v);
$msg.=" $vn";
}
} else {
$val = stripslashes($val);
$msg.="$key: $valn";
}
}
$recipient="[email protected]";
$subject="Form submission";
error_reporting(0);
if (mail($recipient, $subject, $msg)){
echo "Thanks for the information. 

n";
echo nl2br($input);
} else
echo "An error occurred and the message could not be sent.";
} else
echo "Bad request method";
?>

HTML element names are supposed to be unique, if I remember correctly. Try giving each input element a unique name.

If I make the element names unique, the script in “estimator” does not work.

The dilema is to keep the script that does the calculations working and figure out how to identify which checkboxes the use checked, or rewrite the script so that unique element names can be sent via the post.

Sponsor our Newsletter | Privacy Policy | Terms of Service