Plain contactform example (K2) for K3?

I would like to update the mini plugin to make it work with the K3 version…

I tried several solutions but none works… :disappointed_relieved: a charitable soul?
Thank you. :slightly_smiling_face:

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');

};

I don’t have time to look into this now, but one thing

  • the r class doesn’t exist anymore, so r::is() will not work anymore and must be replaced
  • then the email stuff, there is documentation about that