This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
In the [[https://octobercms.com/docs/ajax/extras|documentation]] is written
You may specify the data-request-validate attribute on a form to enable validation features. <form data-request="onSubmit" data-request-validate>
and
Inside the form, you may display the first error message by using the data-validate-error attribute on a container element. The content inside the container will be set to the error message and the element will be made visible.
I also tried this
To display multiple error messages, include an element with the data-message attribute. In this example the paragraph tag will be duplicated and set with content for each message that exists.
<div class="alert alert-danger" data-validate-error> <p data-message></p> </div>
But that outputs nothing
My form:
<div data-validate-error></div>
<div class="alert alert-danger" data-validate-error>
<p data-message></p>
</div>
<form data-request="onSend" data-request-validate>
<label>{{ 'contactform.name'|_ }}</label>
<input type="text" name="name">
<label>{{ 'contactform.email'|_ }}</label>
<input type="email" name="email">
<label>{{ 'contactform.message'|_ }}</label>
<textarea name="content"></textarea>
<button type="submit">{{ 'contactform.send'|_ }}</button>
</form>
and my onSend:
public function onSend() {
$messages = [
'name.required' => trans('david.contact::lang.plugin.contact.components.contactform.validation.name.required'),
'name.min' => trans('david.contact::lang.plugin.contact.components.contactform.validation.name.min'),
'email.required' => trans('david.contact::lang.plugin.contact.components.contactform.validation.email.required'),
'email.email' => trans('david.contact::lang.plugin.contact.components.contactform.validation.email.email'),
'message.required' => trans('david.contact::lang.plugin.contact.components.contactform.validation.message.required'),
];
$validator = Validator::make(
[
'name' => Input::get('name'),
'email' => Input::get('email'),
'message' => Input::get('content')
],
[
'name' => 'required|min:8',
'email' => 'email|required',
'message' => 'required'
],
$messages
);
if ($validator->passes()) {
$vars = [
'name' => Input::get('name'),
'email' => Input::get('email'),
'content' => Input::get('content')
];
Mail::send('david.contact::mail.message', $vars, function($message) {
$to = $this->property('to');
$subject = trans('david.contact::lang.plugin.contact.components.contactform.subject');
$message->to($to, 'adim');
$message->subject($subject);
});
} else {
// throw new ValidationException(['name' => 'You must give a name!']);
}
Can anyone help?
I should mention, that I'm calling the form in my Component and the onSend() is in my ContactForm.php (<-- the Comonent Class file)-
Last updated
I've got it!!!
An example is in the documentation, but not in the validation section but in the [[https://octobercms.com/docs/ajax/extras|extra features-Section]]
And the second error I made is
...
use use Illuminate\Validation\ValidationException;
...
throw new ValidationException(['name' => 'You must give a name!']);
...
which only opened a Popup with a strange error Message. I had to use
use Validation;
Last updated
1-3 of 3