Last active
January 8, 2016 13:42
-
-
Save janstieler/795435e899bc1df31268 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return function($site, $pages, $page, $data) { | |
$contactalert = null; | |
if(get('contactsubmit')) { | |
$contactdata = array( | |
/* 'contactaktion' => get('contactaktion'), */ | |
'contactname' => get('contactname'), | |
'contactemail' => get('contactemail'), | |
'contactsubject' => get('contactsubject'), | |
'contacttext' => get('contacttext'), | |
/* 'contactcaptcha' => get('contactcaptcha'), */ | |
); | |
$contactrules = array( | |
'contactname' => array('required'), | |
'contactemail' => array('required', 'email'), | |
'contacttext' => array('required', 'min' => 3, 'max' => 3000), | |
/* 'contactcaptcha' => array('required', 'captcha'), */ | |
); | |
$contactmessages = array( | |
'contactname' => l::get('namerror_contact'), | |
'contactemail' => l::get('emailerror_contact'), | |
'contacttext' => l::get('texterror_contact'), | |
/* 'contactcaptcha' => l::get('captchaerror_contact'), */ | |
); | |
// some of the data is invalid | |
if($contactinvalid = invalid($contactdata, $contactrules, $contactmessages)) { | |
$contactalert = $contactinvalid; | |
// the data is fine, let's send the email | |
} else { | |
// create the body from a simple snippet | |
$contactbody = snippet('contactmail', $contactdata, true); | |
// build the email | |
$contactemail = email(array( | |
'to' => 'test@foobar', | |
'subject' => utf8_decode ('Kontaktanfrage'), | |
'replyTo' => utf8_decode ($contactdata['contactemail']), | |
'body' => utf8_decode ($contactbody) | |
)); | |
// try to send it and redirect to the | |
// thank you page if it worked | |
if($contactemail->send()) { | |
go('/contact-thank-you'); | |
// add the error to the alert list if it failed | |
} else { | |
$contactalert = array($contactemail->error()); | |
} | |
} | |
} | |
return compact('contactalert'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment