Skip to content

Commit c05a58b

Browse files
committed
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()).
1 parent 1571a62 commit c05a58b

File tree

5 files changed

+40
-36
lines changed

5 files changed

+40
-36
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ignore html files that are used for form testing.
2+
*.htm
3+
*.html
4+
5+
#ignore shell scripts (I have one setup to rsync changed
6+
#files to my hosting account for testing.)
7+
8+
*.sh

config.php

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//------------EVERYTHING BELOW THIS POINT IS OPTIONAL---------------
77

88
//This is the name of the file to use when no template is passed.
9+
//Useful if you're pointing multiple contacts to the same form.
10+
911
$templateFile = 'template.txt'; //Default is template.txt
1012

1113
//This is the default page that should show after the information is submitted.

form.html

-29
This file was deleted.

process.php

+27-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,32 @@
22

33
require_once('config.php');
44

5+
function templateLogic($matches)
6+
{
7+
$temp = trim($matches[0], "{}");
8+
9+
if(isset($_POST[$temp]))
10+
{
11+
return $_POST[$temp];
12+
}
13+
elseif($temp == "phpfEVERYTHING")
14+
{
15+
foreach($_POST as $key => $value)
16+
{
17+
if($key == "recaptcha_challenge_field"
18+
|| $key == "recaptcha_response_field")
19+
{
20+
continue;
21+
}
22+
$everything .= $key.": ".$value."<br>\n";
23+
}
24+
25+
return $everything;
26+
}
27+
28+
return "{TEMPLATE FIELD NOT SPECIFIED}";
29+
}
30+
531

632
if($recaptchaEnabled)
733
{
@@ -48,12 +74,7 @@
4874
foreach($template as $line)
4975
{
5076
$emailBody .= preg_replace_callback(
51-
$pattern, create_function(
52-
'$matches',
53-
'$temp = trim($matches[0], "{}");'.
54-
'if(isset($_POST[$temp])){'.
55-
'return $_POST[$temp];}'.
56-
'echo $_POST[$temp]; return "{NOT SPECIFIED}";'),
77+
$pattern, "templateLogic",
5778
$line);
5879
}
5980

template.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
The {adjective1} {adjective2} {animal1} {verb} over the {adjective3} {animal2}.
1+
New form submition from {email}
2+
3+
{phpfEVERYTHING}
24

0 commit comments

Comments
 (0)