From c05a58b4d631da224c852f85330d24844c2a1d68 Mon Sep 17 00:00:00 2001 From: John Shaver Date: Tue, 1 Jun 2010 01:03:57 -0600 Subject: [PATCH] Added a default template.txt file and the phpfEVERYTHING template option. Needs documentation. I also changed the template logic function to a real function instead of the anonymous function it was (templateLogic()). --- .gitignore | 8 ++++++++ config.php | 2 ++ form.html | 29 ----------------------------- process.php | 33 +++++++++++++++++++++++++++------ template.txt | 4 +++- 5 files changed, 40 insertions(+), 36 deletions(-) create mode 100644 .gitignore delete mode 100644 form.html 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}