Add options to ignore empty fields.
This commit is contained in:
parent
288501be64
commit
f4bfcc175f
21
sendform.php
21
sendform.php
|
|
@ -1,8 +1,5 @@
|
|||
<?php
|
||||
/************************************************************************
|
||||
* SendForm Version 0.99.1 *
|
||||
* Created 10 May 2005 *
|
||||
* Modified 17 Oct 2017 *
|
||||
* Questions/Comments: eric.fawcett@gmail.com *
|
||||
* *
|
||||
* COPYRIGHT NOTICE *
|
||||
|
|
@ -38,6 +35,11 @@
|
|||
// NOTE: The field "recipient" is required by this script and will always be checked.
|
||||
$defaultReq = "";
|
||||
|
||||
// $defaultIgnoreEmpty is either true or false. If true, the script will ignore all empty fields
|
||||
// and return only fields that contain data. Useful if you have a number optional fields and do not
|
||||
// want to output them to the resulting email.
|
||||
$defaultIgnoreEmpty = false;
|
||||
|
||||
// $smtpEnable enables or disables the SMTP sending method. enter 1 to turn it on or 0 to turn it off
|
||||
// $smtpHost, $smtpUser, $smtpPass only need to be filled if $smtpEnable is set to 1
|
||||
$smtpEnable = "0";
|
||||
|
|
@ -57,7 +59,7 @@
|
|||
else $defaultReq = "recipient";
|
||||
|
||||
$referals = explode(",", $referals);
|
||||
$excludeFields = explode(",", "recipient, ccrecipient, bccrecipient, subject, required, redirect, mailtemplate, mailtemplatehtml, submit, submit_x, submit_y, verification, " . $excludeFields);
|
||||
$excludeFields = explode(",", "recipient, ccrecipient, bccrecipient, subject, required, redirect, mailtemplate, mailtemplatehtml, submit, submit_x, submit_y, verification, ignoreempty, " . $excludeFields);
|
||||
$srequired = explode(",", $defaultReq);
|
||||
|
||||
$errMsgStyle = "font-family: Arial;
|
||||
|
|
@ -86,6 +88,11 @@
|
|||
else
|
||||
$subject = $defaultSubject;
|
||||
|
||||
if(isset($_POST['ignoreempty']) && ($_POST('ignoreempty') === true || $_POST('ignoreempty') === false))
|
||||
$ignoreempty = $_POST['ignoreempty'];
|
||||
else
|
||||
$ignoreempty = $defaultIgnoreEmpty;
|
||||
|
||||
if(isset($_POST['email']) && trim($_POST['email']) != "")
|
||||
$fromemail = $_POST['email'];
|
||||
else
|
||||
|
|
@ -163,9 +170,10 @@
|
|||
}
|
||||
|
||||
function writestandard() {
|
||||
global $message, $theDomain;
|
||||
global $message, $theDomain, $ignoreempty;
|
||||
$message="Here is the information collected:\n\n";
|
||||
foreach($_POST as $varname => $varval) {
|
||||
if($ignoreempty===true && empty($varval)) continue;
|
||||
if(is_array($varval)) $varval = implode(", ",$varval);
|
||||
if(!exclude($varname)) {
|
||||
$message .= "$varname: ";
|
||||
|
|
@ -184,12 +192,13 @@
|
|||
}
|
||||
|
||||
function writetemplate($thefile) {
|
||||
global $message, $theDomain;
|
||||
global $message, $theDomain, $ignoreempty;
|
||||
$thearray = Array();
|
||||
if($fp = @fopen($thefile, 'r')) {
|
||||
while($data = fgets($fp, 1024)) {
|
||||
$data = chop($data);
|
||||
foreach($_POST as $varname => $varval) {
|
||||
if($ignoreempty===true && empty($varval)) continue;
|
||||
if(is_array($varval)) $varval = implode(", ",$varval);
|
||||
$data = str_replace("[$varname]", $varval, $data);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue