the mail() function
Moderators: macek, egami, gesf
by Inky1231 » Thu Jan 19, 2012 11:14 am
I posted another question with this same form, but I am trying to figure out how to get the form to leave out blank form fields.
- Code: Select all
<p class="style2"><span class="style5"><strong>Incident / Unusual Occurrence Report</strong></span><br>
Danville Area Community College<br><br>
REPORT FORM</p>
<table width="481" height="657" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td rowspan="2" valign="top" bgcolor="#FFFFFF" style="width: 481px">
<p align="center"class="style3"><font size="-1" face="Arial, Helvetica, sans-serif" align="left">
<?php
$problems = array();
$showform = 0;
$errorMessage = "";
function validate($field, $value) {
// || $field == "id" || $field == "phone" || $field == "course" || $field == "instructor"
/*if ($field == "name" || $field == "email" || $field == "computers" || $field == "info") {*/
if ($value == "") {
return 0;
} else {
return 1;
}
/*}*/
/*if ($field == "system" || $field == "browser" || $field == "issue" || $field == "multiple") {
if ($value == "----" || $value == "") {
return 0;
} else {
return 1;
}
}*/
}
if($_POST) {
//'id','phone','course','instructor',
$fields = array('name','title', 'date', 'time', 'building', 'room', 'location', 'person', 'title1', 'phone1', 'explanation', 'security', 'police', 'witness',);
$x = 0 - 1;
foreach($fields as $field) {
if(isset($_POST[$field])) {
$validation = validate($field, $_POST[$field]);
if ($validation == 1) {
$x++;
$info[$x] = $_POST[$field];
} else {
$problems[$field] = 1;
$showform = 1;
}
} else {
$problems[$field] = 1;
$showform = 1;
}
}
} else {
$showform = 1;
}
if(count($problems) < 1 && $_POST) {
// DO THE MAILING HERE
$fields = array('title', 'name','date', 'time', 'building', 'room', 'location', 'title1','person', 'phone1', 'title2', 'person2', 'phone2','title3','person3', 'phone3','title4','person4', 'phone4', 'type1', 'type2', 'type3', 'type4', 'type5', 'type6', 'type7', 'type8', 'type9', 'explanation', 'security', 'police', 'wtitle1', 'wperson', 'wphone1', 'wtitle2', 'wperson2', 'wphone2','wtitle3','wperson3', 'wphone3',);
$to = "ampeck@earthlink.net";
$to2 = "aabdelzaher@dacc.edu";
$subject = "Incident / Unusual Occurrence Report";
$headers = "From: noreply@dacc.edu\r\n" . "X-Mailer: php";
$greet = "The following was submitted on " . date("F j, Y, g:i a") . "\n\n";
$body = $greet ;
$cn = 1;
foreach($fields as $efield) {
if(isset($_POST[$efield])) {
if($efield == "type1" || $efield == "type2" || $efield == "type3" || $efield == "type4" || $efield == "type5" || $efield == "type6" || $efield == "type7" || $efield == "type8" || $efield == "type9" ) {
$body.= "Type of Occurrence:" . $_POST[$efield] . "\n\n";
$cn++;
} elseif($efield == "title") {
$body.= "Name of Person Filing Report: " . $_POST[$efield] . " ";
} elseif($efield == "name") {
$body.= " " . $_POST[$efield] . "\n________________________________________\n\n";
} elseif($efield == "date") {
$body.= "Date of Occurrence: " . $_POST[$efield] . " \t ";
} elseif ($efield == "time") {
$body.= "Time: " . $_POST[$efield] . "\n________________________________________\n\n";
} elseif ($efield == "building") {
$body.= "Building: " . $_POST[$efield] . " \t\t ";
} elseif ($efield == "room") {
$body.= "Room: " . $_POST[$efield] . "\n\n";
} elseif ($efield == "location") {
$body.= "Description of Location: " . $_POST[$efield] . "\t\r\n________________________________________\n\n";
} elseif ($efield == "title1") {
$body.= "First Person involved: " . $_POST[$efield] . " ";
} elseif ($efield == "person") {
$body.= " \t" . $_POST[$efield] . "\n";
} elseif ($efield == "phone1") {
$body.= "Phone : " . $_POST[$efield] . "\n________________________________________\n\n";
}elseif ($efield == "title2") {
$body.= "Second Person involved: " . $_POST[$efield] . " ";
} elseif ($efield == "person2") {
$body.= " " . $_POST[$efield] . "\n";
} elseif ($efield == "phone2") {
$body.= "Phone : " . $_POST[$efield] . "\n________________________________________\n\n";
} elseif ($efield == "title3") {
$body.= "Third Person involved: " . $_POST[$efield] . " ";
} elseif ($efield == "person3") {
$body.= " " . $_POST[$efield] . "\n";
} elseif ($efield == "phone3") {
$body.= "Phone: " . $_POST[$efield] . "\n________________________________________\n\n";
} elseif ($efield == "title4") {
$body.= "Fourth Person Involved: " . $_POST[$efield] . " ";
} elseif ($efield == "person4") {
$body.= " " . $_POST[$efield] . " \n";
} elseif ($efield == "phone4") {
$body.= "Phone: " . $_POST[$efield] . "\n________________________________________\n\n";
} elseif ($efield == "explanation") {
$body.= "Detailed Explanation: " . $_POST[$efield] . "\t\r\n________________________________________\n\n";
} elseif ($efield == "security") {
$body.= "Security called: " . $_POST[$efield] . "\t\r";
} elseif ($efield == "police") {
$body.= "Police called: " . $_POST[$efield] . "\t\r";
} elseif ($efield == "witness") {
$body.= "Were there witnesses: " . $_POST[$efield] . "\t\r";
} elseif($efield == "wtitle1") {
$body.= "Witness: " . $_POST[$efield] . " ";
} elseif ($efield == "wperson") {
$body.= " \t" . $_POST[$efield] . "\n";
} elseif ($efield == "wphone1") {
$body.= "Phone : " . $_POST[$efield] . "\n________________________________________\n\n";
}elseif ($efield == "wtitle2") {
$body.= "Second witness: " . $_POST[$efield] . " ";
} elseif ($efield == "wperson2") {
$body.= " " . $_POST[$efield] . "\n";
} elseif ($efield == "wphone2") {
$body.= "Phone : " . $_POST[$efield] . "\n________________________________________\n\n";
} elseif ($efield == "wtitle3") {
$body.= "Third witness: " . $_POST[$efield] . " ";
} elseif ($efield == "wperson3") {
$body.= " " . $_POST[$efield] . "\n";
} elseif ($efield == "wphone3") {
$body.= "Phone: " . $_POST[$efield] . "\n________________________________________\n\n";
}
}
}
mail($to, $subject, $body, $headers);
mail($to2, $subject, $body, $headers);
?>
<p class="style1">Your report has been submitted.<br><br></p>
<?php
}
if($showform == 1) {
?>
-
Inky1231
- New php-forum User

-
- Posts: 23
- Joined: Thu Jan 19, 2012 8:01 am
by bigjoe11a » Sun Jan 29, 2012 6:59 pm
When a user fills out the form and clicks the submit button. Any parts of the form the user doesn't fill out will be empty or null any way. So I don't under stand your question.
-

bigjoe11a
- New php-forum User

-
- Posts: 128
- Joined: Wed Aug 31, 2011 3:55 am
- Location: USA
-
by Inky1231 » Mon Jan 30, 2012 11:00 am
Bigjoe, basically I didn't want anything to post to the email like the title of the field "Title:" etc.. if there wasn't something in the field when submitted. It's all good thought got the answer I needed

-
Inky1231
- New php-forum User

-
- Posts: 23
- Joined: Thu Jan 19, 2012 8:01 am
Return to PHP coding => Mail
Who is online
Users browsing this forum: No registered users and 1 guest