This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
byronsmith
Hi,
I've got a really simple form that I want to simply post back to itself and then mail me the result. I don't want to use the Ajax framework, or develop a plugin just for something so trivial.
My markup:
<form method="post">
<div class="contact">
<div>
<i>{{ errors.first('name') }}</i>
<div>{{ form_text('name', null, {'placeholder': 'Name'}) }}</div>
</div>
<div>
<i>{{ errors.first('email') }}</i>
<div>{{ form_text('email', null, {'placeholder': 'Email'}) }}</div>
</div>
<div>
<i>{{ errors.first('message') }}</i>
<div>{{ form_textarea('message', null, {'placeholder': 'Message'}) }}</div>
</div>
<div><button>Send</button></div>
</div>
</form>
I was hoping I could simply do the following as part of the 'Code' tab, but I'm not having much luck, any ideas?:
function onStart()
{
if (request()->isMethod('post')) {
$validator = Validator::make(
request()->all(),
[
'name' => 'required',
'email' => 'required|email',
'message' => 'required'
]
);
if ($validator->fails()) {
return redirect()->back()->withErrors($validator->messages())->withInput();
}
$data = [
'name' => request()->get('name'),
'email' => request()->get('email'),
'content' => request()->get('message')
];
Mail::send('contact.email', $data, function($message) use ($data) {
$message->from($data['email'], $data['name']);
$message->to('email@gmail.com', 'My Email');
$message->replyTo($data['email'], $data['name']);
});
}
}
Last updated
1-1 of 1