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()).
This commit is contained in:
parent
1571a620a4
commit
c05a58b4d6
5 changed files with 40 additions and 36 deletions
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
|
@ -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
|
|
@ -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.
|
||||
|
|
29
form.html
29
form.html
|
@ -1,29 +0,0 @@
|
|||
<head>
|
||||
<title>This is my title</title>
|
||||
</head>
|
||||
<body>
|
||||
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. <br>
|
||||
<br>
|
||||
Please put everything in past tense unless otherwise stated.<br>
|
||||
<br>
|
||||
<form action='process.php' method='post'>
|
||||
adjective <input type="text" name="adjective1"><br>
|
||||
adjective <input type="text" name="adjective2"><br>
|
||||
animal<input type="text" name="animal1"><br>
|
||||
verb<input type="text" name="verb"><br>
|
||||
adjective<input type="text" name="adjective3"><br>
|
||||
animal<input type="text" name="animal2"><br>
|
||||
|
||||
<script type="text/javascript"
|
||||
src="http://api.recaptcha.net/challenge?k=6LfGEwsAAAAAAEfdb77X7r7gbSJwOlLz44-RW6zA">
|
||||
</script>
|
||||
<noscript>
|
||||
<iframe src="http://api.recaptcha.net/noscript?k=6LfGEwsAAAAAAEfdb77X7r7gbSJwOlLz44-RW6zA"
|
||||
height="300" width="500" frameborder="0"></iframe><br>
|
||||
|
||||
</noscript>
|
||||
|
||||
|
||||
<input type='submit' name='Click here to email me the adlib!'>
|
||||
</form>
|
||||
</body>
|
33
process.php
33
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."<br>\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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
The {adjective1} {adjective2} {animal1} {verb} over the {adjective3} {animal2}.
|
||||
New form submition from {email}
|
||||
|
||||
{phpfEVERYTHING}
|
||||
|
||||
|
|
Loading…
Reference in a new issue