-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Making websites with October CMS - Part 19 - Form Validation
- Loading branch information
Ivan Doric
committed
Oct 26, 2016
1 parent
6a50a20
commit 8816253
Showing
3 changed files
with
57 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
use Cms\Classes\ComponentBase; | ||
use Input; | ||
use Mail; | ||
use Validator; | ||
use Redirect; | ||
|
||
class ContactForm extends ComponentBase | ||
{ | ||
|
@@ -16,15 +18,29 @@ public function componentDetails(){ | |
|
||
|
||
public function onSend(){ | ||
|
||
$vars = ['name' => Input::get('name'), 'email' => Input::get('email'), 'content' => Input::get('content')]; | ||
|
||
Mail::send('watchlearn.contact::mail.message', $vars, function($message) { | ||
|
||
$message->to('[email protected]', 'Admin Person'); | ||
$message->subject('New message from contact form'); | ||
|
||
}); | ||
$validator = Validator::make( | ||
[ | ||
'name' => Input::get('name'), | ||
'email' => Input::get('email') | ||
], | ||
[ | ||
'name' => 'required|min:5', | ||
'email' => 'required|email' | ||
] | ||
); | ||
|
||
if($validator->fails()){ | ||
return Redirect::back()->withErrors($validator); | ||
} else { | ||
$vars = ['name' => Input::get('name'), 'email' => Input::get('email'), 'content' => Input::get('content')]; | ||
|
||
Mail::send('watchlearn.contact::mail.message', $vars, function($message) { | ||
|
||
$message->to('[email protected]', 'Admin Person'); | ||
$message->subject('New message from contact form'); | ||
|
||
}); | ||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
<form data-request="onSend"> | ||
<label>Your name</label> | ||
<input type="text" name="name"> | ||
{{ errors.first('name') }} | ||
|
||
<label>Your email</label> | ||
<input type="email" name="email"> | ||
|
||
{{ errors.first('email') }} | ||
<label>Your message</label> | ||
<textarea name="content"></textarea> | ||
|
||
<button type="submit">Send</button> | ||
|
||
<ul> | ||
{% for error in errors.all() %} | ||
<li>{{ error }}</li> | ||
{% endfor %} | ||
</ul> | ||
</form> |