This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hello all and sorry for bothering you. I am at my very begining with October CMS website developement. I've built a simple contact form taht works great, it validates fields and thow error if they are not ok. My embarassing problem is that I can't show a Success message when the email is sent and the visitors are kinf of confused.
So the contactForm.php file is:
'Contact Form',
'description' => 'Formular contact'
];
}
public function onSend () {
$validator = Validator::make(
[
'name' => input::get('name'),
'phone' => input::get('phone'),
'content' => input::get('content'),
'email' => input::get('email')
],
[
'name' => 'required|min:5',
'phone' => 'required|digits_between:10,30',
'content' => 'required|min:20',
'email' => 'required|email'
]
);
if($validator->fails()) {
//What happens if the validator fails
return Redirect::back()->withErrors($validator);
} else {
// These variables are available inside the message as Twig
$vars = ['name' => input::get('name'), 'email' => input::get('email'), 'company' => input::get('company'), 'phone' => input::get('phone'), 'content' => input::get('content')];
Mail::send('plugin-author.contact::mail.message', $vars, function($message) {
$message->to('the-recipient-email@email.email', 'For');
$message->subject('Subject');
});
}
}
}
The errors are throw out in the components via:
{% for error in errors.all() %}
{{ error }}
{% endfor %}
So here I would like to throw up a "You message has been sent succesfuly" message. Can anyone help me please? The form is submitted via ajax. Thank you in advance. Andrew.
Last updated
In the HTML - else part:
{% flash success %}
<div class="alert alert-success mt-2">{{ message }}</div>
{% endflash %}
In php section after Mail::send()
Flash::success('Email sent successfully!');
return Redirect::refresh();
Last updated
info51276 said:
In the HTML - else part: {% flash success %}
{{ message }}{% endflash %}
In php section after Mail::send()
Flash::success('Email sent successfully!'); return Redirect::refresh();
Thanks for your answer. In the last 2 years since my question was posted, I managed to develop all the things I needed and got pretty good experience with October, including the problem mentioned in this thread.
All the best and have a very nice week!
Last updated
1-3 of 3