如何解决Laravel 7 Ajax验证不刷新
我实际上想知道,有没有一种方法可以在不刷新页面的情况下验证表单数据?
您知道在键入电子邮件并等待10秒钟以刷新页面时,这太繁琐了,然后这是不正确的。好吧,我在某处听说过,有一个没有任何重定向/刷新的验证及其在AJAX
上的验证,但是我什至不知道它是什么。甚至我假设使用validator
编写代码都有些复杂。好吧,这是我的验证器代码:
$this->validate($request,[
'name' => 'required','email' => 'required|email','phone' => 'required','subject'=>'required','contact_method_vk' => 'required_if:subject,VK','message' => 'required'
]);
和我的表格。有人可以给我一个提示,如何在Ajax中准确编写此验证表单吗?
<form class="form_contact" action="/#about-us" method="post" action="{{ route('contact.store') }}">
@csrf
<input @if ($errors->has('name')) style="border-color: red" @endif placeholder="Имя" class="form_control"type="text" name="name" id="name">
<!-- Error -->
@if ($errors->has('name'))
<div class="error">
{{ $errors->first('name') }}
</div>
@endif
<input @if ($errors->has('email')) style="border-color: red" @endif placeholder="Email" class="form_control"type="email" name="email" id="email">
@if ($errors->has('email'))
<div class="error">
{{ $errors->first('email') }}
</div>
@endif
<input @if ($errors->has('phone')) style="border-color: red" @endif placeholder="Телефон" class="form_control" type="text" name="phone" id="phone">
@if ($errors->has('phone'))
<div class="error">
{{ $errors->first('phone') }}
</div>
@endif
<div @if ($errors->has('subject')) class="invalid_select" @else class="select" @endif>
<select placeholder="Как с Вами связаться" type="text" name="subject" id="subject">
<option selected disabled value="Способ связи">Способ связи</option>
<option id="VK" name="VK" value="VK">VK</option>
<option id="Viber" name="Viber" value="Viber">Viber</option>
<option id="WhatsApp" name="WhatsApp" value="WhatsApp">WhatsApp</option>
</select>
</div>
@if ($errors->has('subject'))
<div class="error">
{{ $errors->first('subject') }}
</div>
@endif
<input @if ($errors->has('contact_method_vk')) style="border-color: red" @endif placeholder="id" style="display:none;" type="text" class="musician_input_div form_control" type="text" name="contact_method_vk" id="contact_method_vk"/>
@if ($errors->has('contact_method_vk'))
<div id="musician_input_div" class="error">
{{ $errors->first('contact_method_vk') }}
</div>
@endif
<textarea @if ($errors->has('message')) style="border-color: red" @endif placeholder="Краткое описание проблемы" class="form_control height" name="message" id="message" rows="4"></textarea>
@if ($errors->has('message'))
<div class="error">
{{ $errors->first('message') }}
</div>
@endif
<button class="form_control_submit" type="submit" name="send">Отправить</button>
</form>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。