<h3 class="mb-lg-4">Request A Call Back</h3>
 <div id="validation-errors" ></div>
<div class="form-group">
    <input type="text" name="name" id="name" class="form-control" placeholder="Your Name">
</div>
<div class="form-group">
    <input type="text" name="phone" id="phone" class="form-control" placeholder="Your Phone Number">
</div>
<div class="form-group">
    <input type="email" name="email" id="email" class="form-control" placeholder="Your Email Address">
</div>
<div class="form-group">
    <textarea name="message" rows="3" id="message" class="form-control" placeholder="Your Message"></textarea>
</div>
<div class="form-group text-center">
    <button class="btn btn-lg btn-primary save"><i class="far fa-hand-point-right mr-1"></i>Send To Our Team</button>
</div>

@section('myscript')
<script>
    $(document).ready(function ()
    {

        $(".save").click(function () {
            $(".save").attr("disabled", true);
            var fd = new FormData();
            fd.append('name', $("#name").val());
            fd.append('email', $("#email").val());
            fd.append('phone', $("#phone").val());
            fd.append('message', $("#message").val());
            fd.append('_token', "{{ csrf_token() }}");


            $.ajax({

                url: "{{url('equiry')}}",
                type: 'post',
                data: fd,
                dataType: "json",
                contentType: false,
                processData: false,
                success: function (response) {

                    if (response.success == true) {
                        $('#name').val("");
                        $('#email').val("");
                        $('#phone').val("");
                        $('#message').val("");
                        $('#validation-errors').empty();

                        $(".save").attr("disabled", false);

                        window.top.location.href = '{{url("thank-you")}}';
                    } else {
                    }
                },

                error: function (xhr) {
                  
                    $('#validation-errors ').html('');

                    errorsHtml = '<div class="alert alert-danger"><ul>';
                    $.each(xhr.responseJSON.errors, function (key, value) {
                        errorsHtml += '<li>' + value[0] + '</li>';
                        //showing only the first error.
                      
                    });
                       
                        $(".save").attr("disabled", false);

                          errorsHtml += '</ul></div>';
                          $('#validation-errors').append(errorsHtml); //appending to a <div id="form-errors"></div> inside form


                },
            });
        });
    });
</script>
@endsection