Skip to content

Commit

Permalink
Making websites with October CMS - Part 19 - Form Validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Doric committed Oct 26, 2016
1 parent 6a50a20 commit 8816253
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 152 deletions.
167 changes: 25 additions & 142 deletions octobermovies.sublime-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -519,38 +519,11 @@
},
"buffers":
[
{
"file": "plugins/watchlearn/contact/Plugin.php",
"settings":
{
"buffer_size": 312,
"encoding": "UTF-8",
"line_ending": "Unix"
}
},
{
"file": "plugins/watchlearn/contact/views/mail/message.htm",
"settings":
{
"buffer_size": 120,
"encoding": "UTF-8",
"line_ending": "Unix"
}
},
{
"file": "plugins/watchlearn/contact/components/ContactForm.php",
"settings":
{
"buffer_size": 692,
"encoding": "UTF-8",
"line_ending": "Unix"
}
},
{
"file": "config/mail.php",
"settings":
{
"buffer_size": 4432,
"buffer_size": 1149,
"encoding": "UTF-8",
"line_ending": "Unix"
}
Expand All @@ -559,7 +532,7 @@
"file": "plugins/watchlearn/contact/components/contactform/default.htm",
"settings":
{
"buffer_size": 290,
"buffer_size": 461,
"encoding": "UTF-8",
"line_ending": "Unix"
}
Expand Down Expand Up @@ -831,17 +804,21 @@
"expanded_folders":
[
"/Users/ivan/Development/public/octobermovies",
"/Users/ivan/Development/public/octobermovies/config",
"/Users/ivan/Development/public/octobermovies/plugins",
"/Users/ivan/Development/public/octobermovies/plugins/october",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/contact",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/contact/classes",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/contact/components",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/contact/components/contactform",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/contact/views",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/contact/views/mail"
],
"file_history":
[
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/contact/Plugin.php",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/contact/views/mail/message.htm",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/contact/components/contactform/default.htm",
"/Users/ivan/Development/public/octobermovies/config/mail.php",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/movies/components/Actors.php",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/movies/components/actors/default.htm",
Expand Down Expand Up @@ -966,10 +943,7 @@
"/Users/ivan/Development/public/springfall/resources/assets/js/rating.js",
"/Users/ivan/Development/public/springfall/database/migrations/2016_06_09_071152_create_reviews_table.php",
"/Users/ivan/Development/public/springfall/database/migrations/2016_06_09_071307_create_accommodation_review_table.php",
"/Users/ivan/Development/public/springfall/app/Http/Controllers/Auth/AuthController.php",
"/Users/ivan/Development/public/springfall/database/migrations/2016_05_31_101837_add_additional_fields_to_users_table.php",
"/Users/ivan/Development/public/springfall/vendor/laravel/framework/src/Illuminate/Foundation/Auth/RegistersUsers.php",
"/Users/ivan/Development/public/springfall/resources/views/partials/footer.blade.php"
"/Users/ivan/Development/public/springfall/app/Http/Controllers/Auth/AuthController.php"
],
"find":
{
Expand Down Expand Up @@ -1176,87 +1150,24 @@
"groups":
[
{
"selected": 3,
"selected": 1,
"sheets":
[
{
"buffer": 0,
"file": "plugins/watchlearn/contact/Plugin.php",
"semi_transient": false,
"settings":
{
"buffer_size": 312,
"regions":
{
},
"selection":
[
[
251,
251
]
],
"settings":
{
"incomplete_sync": null,
"remote_loading": false,
"synced": false,
"syntax": "Packages/PHP/PHP.sublime-syntax"
},
"translation.x": 0.0,
"translation.y": 0.0,
"zoom_level": 1.0
},
"stack_index": 2,
"type": "text"
},
{
"buffer": 1,
"file": "plugins/watchlearn/contact/views/mail/message.htm",
"semi_transient": false,
"settings":
{
"buffer_size": 120,
"regions":
{
},
"selection":
[
[
115,
115
]
],
"settings":
{
"_anf_new": "",
"incomplete_sync": null,
"remote_loading": false,
"synced": false,
"syntax": "Packages/Twig/Syntaxes/HTML (Twig).tmLanguage"
},
"translation.x": 0.0,
"translation.y": 0.0,
"zoom_level": 1.0
},
"stack_index": 3,
"type": "text"
},
{
"buffer": 2,
"file": "plugins/watchlearn/contact/components/ContactForm.php",
"semi_transient": false,
"settings":
{
"buffer_size": 692,
"buffer_size": 1149,
"regions":
{
},
"selection":
[
[
578,
578
629,
629
]
],
"settings":
Expand All @@ -1268,63 +1179,31 @@
"syntax": "Packages/PHP/PHP.sublime-syntax"
},
"translation.x": 0.0,
"translation.y": 689.0,
"translation.y": 797.0,
"zoom_level": 1.0
},
"stack_index": 1,
"type": "text"
},
{
"buffer": 3,
"file": "config/mail.php",
"semi_transient": false,
"settings":
{
"buffer_size": 4432,
"regions":
{
},
"selection":
[
[
3930,
3930
]
],
"settings":
{
"incomplete_sync": null,
"remote_loading": false,
"synced": false,
"syntax": "Packages/PHP/PHP.sublime-syntax"
},
"translation.x": 0.0,
"translation.y": 4548.0,
"zoom_level": 1.0
},
"stack_index": 0,
"type": "text"
},
{
"buffer": 4,
"buffer": 1,
"file": "plugins/watchlearn/contact/components/contactform/default.htm",
"semi_transient": false,
"settings":
{
"buffer_size": 290,
"buffer_size": 461,
"regions":
{
},
"selection":
[
[
28,
28
92,
92
]
],
"settings":
{
"_anf_new": "",
"incomplete_sync": null,
"remote_loading": false,
"synced": false,
Expand All @@ -1334,7 +1213,7 @@
"translation.y": 0.0,
"zoom_level": 1.0
},
"stack_index": 4,
"stack_index": 0,
"type": "text"
}
]
Expand Down Expand Up @@ -1910,15 +1789,19 @@
"select_project":
{
"height": 500.0,
"last_filter": "wat",
"last_filter": "watc",
"selected_items":
[
[
"wat",
"watc",
"~/Development/public/watchlearn/watchlearn.sublime-project"
],
[
"watc",
"g",
"~/Development/public/gaussdev/gaussdev.sublime-project"
],
[
"wat",
"~/Development/public/watchlearn/watchlearn.sublime-project"
],
[
Expand Down
34 changes: 25 additions & 9 deletions plugins/watchlearn/contact/components/ContactForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use Cms\Classes\ComponentBase;
use Input;
use Mail;
use Validator;
use Redirect;

class ContactForm extends ComponentBase
{
Expand All @@ -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');

});
}

}

Expand Down
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>

0 comments on commit 8816253

Please sign in to comment.