Skip to content

Instantly share code, notes, and snippets.

@janstieler
Last active January 8, 2016 13:42
Show Gist options
  • Save janstieler/795435e899bc1df31268 to your computer and use it in GitHub Desktop.
Save janstieler/795435e899bc1df31268 to your computer and use it in GitHub Desktop.
<?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