diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bafc1ff --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +#ignore html files that are used for form testing. +*.htm +*.html + +#ignore shell scripts (I have one setup to rsync changed +#files to my hosting account for testing.) + +*.sh diff --git a/config.php b/config.php index 5074322..734295d 100644 --- a/config.php +++ b/config.php @@ -6,6 +6,8 @@ $sendToEmail = 'your@email.com'; //------------EVERYTHING BELOW THIS POINT IS OPTIONAL--------------- //This is the name of the file to use when no template is passed. +//Useful if you're pointing multiple contacts to the same form. + $templateFile = 'template.txt'; //Default is template.txt //This is the default page that should show after the information is submitted. diff --git a/form.html b/form.html deleted file mode 100644 index ada1fd4..0000000 --- a/form.html +++ /dev/null @@ -1,29 +0,0 @@ - - This is my title - - - This form is for testing out my templating for my mail script. It's an addlib of one of my sister's fan fics she wrote. Feel free to fill it out and it will send the addlib to me.
-
- Please put everything in past tense unless otherwise stated.
-
-
- adjective
- adjective
- animal
- verb
- adjective
- animal
- - - - - - -
- diff --git a/process.php b/process.php index d78a5be..0758920 100644 --- a/process.php +++ b/process.php @@ -2,6 +2,32 @@ require_once('config.php'); +function templateLogic($matches) +{ + $temp = trim($matches[0], "{}"); + + if(isset($_POST[$temp])) + { + return $_POST[$temp]; + } + elseif($temp == "phpfEVERYTHING") + { + foreach($_POST as $key => $value) + { + if($key == "recaptcha_challenge_field" + || $key == "recaptcha_response_field") + { + continue; + } + $everything .= $key.": ".$value."
\n"; + } + + return $everything; + } + + return "{TEMPLATE FIELD NOT SPECIFIED}"; +} + if($recaptchaEnabled) { @@ -48,12 +74,7 @@ $pattern = "/\{([a-zA-Z0-9_]+)\}/i"; foreach($template as $line) { $emailBody .= preg_replace_callback( - $pattern, create_function( - '$matches', - '$temp = trim($matches[0], "{}");'. - 'if(isset($_POST[$temp])){'. - 'return $_POST[$temp];}'. - 'echo $_POST[$temp]; return "{NOT SPECIFIED}";'), + $pattern, "templateLogic", $line); } diff --git a/template.txt b/template.txt index 2b42b00..ff44ded 100644 --- a/template.txt +++ b/template.txt @@ -1,2 +1,4 @@ -The {adjective1} {adjective2} {animal1} {verb} over the {adjective3} {animal2}. +New form submition from {email} + +{phpfEVERYTHING}