Want to send form via email but only inc. completed fields
Posted: Thu Aug 07, 2003 5:05 am
Hi all,
I have a php page that has a submit form whose contents are emailed when submitted. The form is for people to submit bird records (the website is for a bird club) and I'm adapting the form to include several boxes to allow entering of more than one record, one on each row. There is a bit of Java in there too for a calendar and "required fields". At the moment it works but emails everything to specified recipients, regardless of what is entered in the boxes. The code is below and at the moment only includes two species rows for brevity.
What I want to be able to do is amend the script so that it only includes completed rows from the form. This would be decided by whether the person has entered a species name in the "rowxspecies" box. I'm a complete newbie to php so any help would be much appreciated please!
Thanks very much,
Gareth
I have a php page that has a submit form whose contents are emailed when submitted. The form is for people to submit bird records (the website is for a bird club) and I'm adapting the form to include several boxes to allow entering of more than one record, one on each row. There is a bit of Java in there too for a calendar and "required fields". At the moment it works but emails everything to specified recipients, regardless of what is entered in the boxes. The code is below and at the moment only includes two species rows for brevity.
What I want to be able to do is amend the script so that it only includes completed rows from the form. This would be decided by whether the person has entered a species name in the "rowxspecies" box. I'm a complete newbie to php so any help would be much appreciated please!
Thanks very much,
Gareth
Code: Select all
<?php
$day = date("d",time());
$month = date("m",time());
$year = date("Y",time());
$grab_time=`date +%H:%M:%S`;
$TO = "user@domain.com";
$MP = "/usr/lib/sendmail -t";
if ($formFill){
$CHECK= strstr ($from, '@');
$CHECK1= strstr ($CHECK, '.');
if ( ( ereg( "(ї~!#$%^&*])", $EMAIL)) || (!$CHECK) || ($CHECK == "@") ||
(!$CHECK1) )
{
print "Sorry $from is not a valid email address. Please click on the browser 'back' button to go back and correct it. \n Thanks!"."<br>\n";
exit;
}
$fd = popen($MP,"w");
fputs($fd, "To: $TO\n");
fputs($fd, "Cc: $CC\n");
fputs($fd, "From: $from\n");
fputs($fd, "Sender: $from\n");
fputs($fd, "Subject: Website Bird Record Submission\n");
fputs($fd, "X-Mailer: Bird Club form\n");
fputs($fd, "Content-Type: text/html; charset=us-ascii\n");
fputs($fd, "Content-Transfer-Encoding: 7bit\n");
fputs($fd, "Submitted by $name at $grab_time on $day/$month/$year<br>");
fputs($fd, "Email address - $from <br><br>");
fputs($fd, "$row1species, $site, $name, $date, $row1count, $row1comment\n<br>");
fputs($fd, "$row2species, $site, $name, $date, $row2count, $row2comment\n");
pclose($fd);
exit;
}else{
echo "<html>";
echo "<body>";
echo "
<body bgcolor=#8FBC8F LINK=#483D8B VLINK=#FFCC00>
<head>
<script language=javascript src=cal2.js>
/*
Xin's Popup calendar script- Xin Yang (http://www.yxscripts.com/)
Script featured on/available at http://www.dynamicdrive.com/
*/
</script>
<script language=javascript src=cal_conf2.js></script>
<script language="JavaScript">
<!--
/*
Required field(s) validation- By NavSurf
Visit NavSurf.com at http://navsurf.com
Visit http://www.dynamicdrive.com for this script
*/
function formCheck(formobj){
if (document.submit.name.value=='') {
alert('Please enter observer name');
document.submit.name.focus();
return false;
}
if (document.submit.from.value=='') {
alert('Please enter your email address');
document.submit.from.focus();
return false;
}
if (document.submit.site.value=='') {
alert('Please select the site');
document.submit.site.focus();
return false;
}
if (document.submit.date.value=='') {
alert('Please choose the date of sightings');
document.submit.date.focus();
return false;
}
}
//-->
</script>
</head>
<p align=center><font size=+3>Submission of bird sightings</p></font>
<form name=submit method="post" action="wibble.php" onsubmit="return formCheck(this);">
<center> <table BGCOLOR=#2F4F4F cellspacing=2 cellpadding=2 border=5>
<tr>
<td align=LEFT><b><font color=white face=Arial, Helvetica, sans-serif size=2>Observer's
name *</font></td>
<td align=left><font face=Arial, Helvetica, sans-serif size=2>
<input type=Text name=name size=30 maxlength=30>
</font></td>
</tr>
<tr>
<td align=LEFT><font color=white face=Arial, Helvetica, sans-serif size=2><b>Observer's
email address *</font></b></td>
<td align=left><font face=Arial, Helvetica, sans-serif size=2>
<input type=Text name=from size=30 maxlength=30>
</font></td>
</tr>
<tr>
<td align=LEFT><font color=white face=Arial, Helvetica, sans-serif size=2><b>Site name *</font></td></b>
<TD><select name=site>
<option></option>
<option value=Amwell>Amwell</option>
<option value=Startops End Reservoir>Startops End Reservoir</option></select>
</td>
</tr>
<tr>
<td align=LEFT><font color=white face=Arial, Helvetica, sans-serif size=2><b>Date of observations *</font></td></b>
<td><input type=text name=date size=10 onclick=javascript:showCal('Calendar1')>
</td></tr>
</table>
<center><font color=white>* denotes required field</font></center>
<br><br>
<center><table cellpadding=2 cellspacing=2 border=5>
<tr BGCOLOR=#2F4F4F>
<td class=normal><b><font color=#FFFFFF>Species </font></b></td>
<td class=normal width=10><b><font color=#FFFFFF>Count </font></b></td>
<td class=size1><b><font color=#FFFFFF>Comments </font></b></td>
</TR>
<TR>
<TD><select name=row1species>
<OPTION></OPTION>
<OPTION>Auk, Little</OPTION><OPTION>Avocet</OPTION><OPTION>Bittern</OPTION><OPTION>Bluethroat</OPTION><OPTION>Duck, Mandarin</OPTION>
</SELECT></TD>
<TD><input type=text name=row1count size=3 value=1></TD>
<TD><textarea name=row1comment rows=1></textarea></td>
</TR>
<TR>
<TD><select name=row2species>
<OPTION></OPTION>
<OPTION>Auk, Little</OPTION><OPTION>Avocet</OPTION><OPTION>Bittern</OPTION><OPTION>Bluethroat</OPTION><OPTION>Duck, Mandarin</OPTION>
</SELECT></TD>
<TD><input type=text name=row2count size=3 value=1></TD>
<TD><textarea name=row2comment rows=1></textarea></td>
</TR>
</table>
<br><br><input type=hidden name=formFill value=formmail><input type=Submit value=Submit record>
</font></td>
<td align=LEFT valign=TOP><font face=Arial, Helvetica, sans-serif size=2>
<input type=reset>
</form>
</body>
</html>";
}
?>