Integrating checkbox into contact form for email submission
Posted: Tue May 02, 2006 12:25 pm
Hi everyone,
I bow to all your php skills. I am completely inept when it comes to php. That's why the script I will be posting is from a script generator. I was able to figure out how to adjust all the fields to be where I like them and fixed the html to fit on my site but I can't seem to integrate a checkbox onto my contact form. All I want someone to be able to do is click a checkbox saying that they want to receive my newsletter. When they click the submit button I want the information "yes" from the checkbox to be sent along with the other contact information. Of course I can place a checkbox there with the code but I can't make it do anything. The checkbox wasn't a part of the generated php script that I got online so I am trying to insert it manually now and I am having a horrible time with it. I know this is base level php stuff but I would greatly appreciate the help.
Here is the html page that I have my php on if anyone needs it: http://www.jonathanhardesty.com/contact.htm
Below is the full code that I have for that htm page including the little php I have on there...I am using dreamweaver and I've heard that it has sloppy coding so sorry if that's true. The php is at the very bottom of this code...I know I don't need to put all of this up here but you never know where the problem might be and I wanted to included everything.:
Below I will also post the code on the "sendeail.php" file that I uploaded to my website server. This is the code exactly as it appears on that file:
I bow to all your php skills. I am completely inept when it comes to php. That's why the script I will be posting is from a script generator. I was able to figure out how to adjust all the fields to be where I like them and fixed the html to fit on my site but I can't seem to integrate a checkbox onto my contact form. All I want someone to be able to do is click a checkbox saying that they want to receive my newsletter. When they click the submit button I want the information "yes" from the checkbox to be sent along with the other contact information. Of course I can place a checkbox there with the code but I can't make it do anything. The checkbox wasn't a part of the generated php script that I got online so I am trying to insert it manually now and I am having a horrible time with it. I know this is base level php stuff but I would greatly appreciate the help.
Here is the html page that I have my php on if anyone needs it: http://www.jonathanhardesty.com/contact.htm
Below is the full code that I have for that htm page including the little php I have on there...I am using dreamweaver and I've heard that it has sloppy coding so sorry if that's true. The php is at the very bottom of this code...I know I don't need to put all of this up here but you never know where the problem might be and I wanted to included everything.:
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Contact Info - Jonathan Hardesty</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
<body bgcolor="#74725f" link="3f2902" vlink="3f2902" alink="3f2902" onLoad="MM_preloadImages('painting2.jpg','drawings2.jpg','lineage2.jpg','contact2.jpg')">
<div align="center">
<pre> <img src="header1.jpg" width="500" height="87">
<img src="space1.jpg" width="33" height="19"><a href="paintings.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image3','','painting2.jpg',1)"><img src="painting1.jpg" name="Image3" width="80" height="19" border="0"></a><img src="space2.jpg" width="35" height="19"><a href="drawings.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image5','','drawings2.jpg',1)"><img src="drawings1.jpg" name="Image5" width="80" height="19" border="0"></a><img src="space3.jpg" width="44" height="19"><a href="lineage.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image7','','lineage2.jpg',1)"><img src="lineage1.jpg" name="Image7" width="65" height="19" border="0"></a><img src="space4.jpg" width="39" height="19"><a href="contact.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image9','','contact2.jpg',1)"><img src="contact1.jpg" name="Image9" width="68" height="19" border="0"></a><img src="space5.jpg" width="56" height="19">
<font size="+2" face="Times New Roman, Times, serif">Jonathan Hardesty
4408 Taylor Lane
Richardson, TX 75082
214-227-6521
jonathan@jonathanhardesty.com
_______________________________________
You may also use the form below to contact me.</font><font size="+1" face="Times New Roman, Times, serif">Code: Select all
<form method="post" action="sendeail.php"><strong>Your Name: </strong><br /><input type="text" name="visitor" size="35" />
<strong>Your Email:</strong><br /><input type="text" name="visitormail" size="35" />
<strong>Mail Message:</strong>
<textarea name="notes" rows="4" cols="40"></textarea>
<input type="submit" value="Send Mail" />
<br /></form></font>
<img src="bottom-lineplusback.jpg" width="500" height="49" border="0" usemap="#Map">
<map name="Map">
<area shape="rect" coords="37,14,102,34" href="index.htm">
</map>
</pre>
</div>
</body>
</html>Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sendemail Script</title>
</head>
<body>
<body bgcolor="#74725f" link="3f2902" vlink="3f2902" alink="3f2902" onLoad="MM_preloadImages('painting2.jpg','drawings2.jpg','lineage2.jpg','contact2.jpg')">
<div align="center">
<pre><img src="header1.jpg" width="500" height="87">
<img src="space1.jpg" width="33" height="19"><a href="paintings.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image3','','painting2.jpg',1)"><img src="painting1.jpg" name="Image3" width="80" height="19" border="0"></a><img src="space2.jpg" width="35" height="19"><a href="drawings.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image5','','drawings2.jpg',1)"><img src="drawings1.jpg" name="Image5" width="80" height="19" border="0"></a><img src="space3.jpg" width="44" height="19"><a href="lineage.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image7','','lineage2.jpg',1)"><img src="lineage1.jpg" name="Image7" width="65" height="19" border="0"></a><img src="space4.jpg" width="39" height="19"><a href="contact.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image9','','contact2.jpg',1)"><img src="contact1.jpg" name="Image9" width="68" height="19" border="0"></a><img src="space5.jpg" width="56" height="19">
<!-- Reminder: Add the link for the 'next page' (at the bottom) -->
<!-- Reminder: Change 'YourEmail' to Your real email -->
<?php
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
}
if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Use Back - fill in all fields</h2>\n";
}
echo $badinput;
$todayis = date("l, F j, Y, g:i a") ;
$notes = stripcslashes($notes);
$message = " $todayis [EST] \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";
$from = "From: $visitormail\r\n";
mail("jonathan@jonathanhardesty.com", $subject, $message, $from);
?>
<p align="center">
Date: <?php echo $todayis ?>
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )
<br />
Message:<br />
<?php $notesout = str_replace("\r", "<br/>", $notes);
echo $notesout; ?>
<br />
<?php echo $ip ?>
<br /><br />
<img src="bottom-lineplusback.jpg" width="500" height="49" border="0" usemap="#Map"><map name="Map">
<area shape="rect" coords="37,14,102,34" href="contact.htm">
</map>
</body>
</html>