Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
evsmash/widgets / libs / Http / Forms.php
Size: Mime:
<?php

namespace Evsmash\Widgets\Http;

use Evsmash\Core\Http\Base;

use Evsmash\Core\Helpers\Redirect;
use Evsmash\Core\Helpers\Http\Notify;
use Evsmash\Core\Input\Post;
use Evsmash\Core\Services\Recaptcha;
use Evsmash\Core\Simpy\Element;
use Evsmash\Core\System\Approval;
use Evsmash\Core\System\Settings;

use Evsmash\Settings\Widget;
use Evsmash\Widgets\Form;
use Evsmash\Widgets\FormSender;
use Evsmash\Widgets\Schemas\Forms as Schema;

class Forms extends Base {

	// sent
	public function sent() {

		// notify check
		if(!Notify::check()) {
			Redirect::to('/');
		}

		// view
		$this->viewTitle('Form sent');
		$this->view();

	}

	// contact
	public function contact() {

		// recaptcha
		Recaptcha::check();

		// widget
		$widget = Element::check(new Widget, Post::get('widget'));

		// recipient
		$settings = settings('widget', ['name' => 'evsmash-widgets-forms-contact', 'id' => $widget->id]);

		// recipients
		if(!Post::get('recipient')) {
			$recipient = $settings->email;
		} else {
			$recipients = Form::recipients($settings->email);
			if(isset($recipients[Post::get('recipient')])) {
				$recipient = $recipients[Post::get('recipient')];
			} else {
				$recipient = 'evsmash@evsmash.com';
			}
		}

		// approvals
		$approvals = Approval::add('evsmash-widgets-approvals-contact', Post::get('email'), Post::get('name'));

		// sender
		$form = new FormSender();
		$form->rules = Schema::validateContact();
		$form->fields = [
			'name' => 'Firstname & surname',
			'email' => 'Email',
			'phone' => 'Phone',
			'message' => 'Message',
		];
		$form->approvals = $approvals;
		$form->title = t('Contact form');
		$form->recipient = $recipient;
		$form->send();

	}

	// message
	public function message() {

		// recaptcha
		Recaptcha::check();

		// widget
		$widget = Element::check(new Widget, Post::get('widget'));

		// recipient
		$settings = settings('widget', ['name' => 'evsmash-widgets-forms-message', 'id' => $widget->id]);

		// approvals
		$approvals = Approval::add('evsmash-widgets-approvals-message', Post::get('email'), Post::get('name'));

		// sender
		$form = new FormSender();
		$form->rules = Schema::validateMessage();
		$form->fields = [
			'email' => 'Email',
			'message' => 'Message',
		];
		$form->approvals = $approvals;
		$form->title = t('Contact form');
		$form->recipient = $settings->email;
		$form->send();

	}

}