I would like to update the mini plugin to make it work with the K3 version…
I tried several solutions but none works… a charitable soul?
Thank you.
Controller code:
<?php
return function($site, $pages, $page) {
$alert = null;
$messages = null;
if(r::is('post') && get('submit')) {
if(!empty(get('website'))) {
go($page->url());
exit;
}
$data = array(
'name' => get('name'),
'email' => get('email'),
'text' => get('text')
);
$rules = array(
'name' => array('required'),
'email' => array('required', 'email'),
'text' => array('required', 'min' => 3, 'max' => 3000),
);
$messages = array(
'name' => 'Please enter a valid name',
'email' => 'Please enter a valid email address',
'text' => 'Please enter a text between 3 and 3000 characters'
);
if($invalid = invalid($data, $rules, $messages)) {
$alert = $invalid;
} else {
$mailto = $page->mailto();
$sender = $page->sender();
$subject = get('subject');
$email = email(array(
'to' => $mailto,
'from' => $sender,
'subject' => $subject,
'replyTo' => $data['name'] . '<'.$data['email'].'>',
'body' => $data['text']
));
if(v::email($mailto) and v::email($sender) and $email->send()) {
$success = array();
$data = array();
} else {
$failed = array();
}
}
}
return compact('alert', 'messages', 'data', 'success', 'failed');
};