-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Contact.php
82 lines (65 loc) · 2.43 KB
/
Contact.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace Igniter\Frontend\Components;
use Admin\Traits\ValidatesForm;
use Exception;
use Location;
use Mail;
use Main\Template\Page;
use Redirect;
use System\Classes\BaseComponent;
class Contact extends BaseComponent
{
use ValidatesForm;
public $location;
public $subjects;
public function defineProperties()
{
return [
'redirectPage' => [
'label' => 'Page to redirect to after contact form has been sent successfully',
'type' => 'select',
'default' => 'contact',
],
];
}
public static function getRedirectPageOptions()
{
return Page::lists('baseFileName', 'baseFileName');
}
public function onRun()
{
$this->location = Location::current();
$this->subjects = ['General enquiry', 'Comment', 'Technical Issues'];
}
public function onSubmit()
{
try {
$rules = [
['subject', 'lang:igniter.frontend::default.contact.text_select_subject', 'required|max:128'],
['email', 'lang:igniter.frontend::default.contact.label_email', 'required|email'],
['full_name', 'lang:igniter.frontend::default.contact.label_full_name', 'required|min:6|max:255'],
['telephone', 'lang:igniter.frontend::default.contact.label_telephone', 'required'],
['comment', 'lang:igniter.frontend::default.contact.label_comment', 'max:1500'],
];
$this->validate(post(), $rules);
$data = [
'full_name' => post('full_name'),
'contact_topic' => post('subject'),
'contact_email' => post('email'),
'contact_telephone' => post('telephone'),
'contact_message' => post('comment'),
];
Mail::queue('igniter.frontend::mail.contact', $data, function ($message) {
$message->to(setting('site_email'), setting('site_name'));
});
flash()->success(lang('igniter.frontend::default.contact.alert_contact_sent'));
$redirectUrl = $this->controller->pageUrl($this->property('redirectPage'));
if ($redirectUrl = get('redirect', $redirectUrl))
return Redirect::to($redirectUrl);
}
catch (Exception $ex) {
flash()->warning($ex->getMessage());
return Redirect::back()->withInput();
}
}
}