0

I'm using Laravel

I have this form items I get validation from database and I'm using jquery for validation all inputs feild have name="element[{{$element->id}}]" (get id from database) I'm trying different method to make validation but it doesn't work

 @if($element->type =='text' && $element->is_depend_on=='0')
            <div class="row">
            <div class="col-sm-12">
            <div class="form-group">
                  <label for="userName">{{$element->label}}</label>
                   <input id="userName" name="element[{{$element->id}}]" type="text"
                       class="form-control @if($element->validation=='required')required @endif" placeholder={{$element->placeholder}}>
                @if($errors->has('element.'.$element->id))
                    <div class="error">{{ $errors->first('element.'.$element->id) }}</div>
                @endif
                    </div>
                </div>
            </div>
            @endif
     @if($element->type =='textarea' &&$element->is_depend_on=='0')
                <div class="row">
                <div class="col-sm-12">
                <div class="form-group">
                     <label for="userName">{{$element->label}}</label>
                     <textarea class="form-control  @if($element->validation=='required')required @endif" name="element[{{$element->id}}]"
                         placeholder={{$element->placeholder}} *="" style="margin: 0px; width: 601px; height: 108px;" spellcheck="false" data-gramm="false"></textarea></div>
                    @if($errors->has('element.'.$element->id))
                        <div class="error">{{ $errors->first('element.'.$element->id) }}</div>
                    @endif
                </div>
                 </div>
               @endif

and here is my js code

var form = $("#order");
   form.validate({
       errorPlacement: function (error, element) {
           error.insertBefore(element);
       },
       rules: {}
   });

also I tried this code

 $("#order").validate({
                rules: {

                },
                messages: {
                }
            });

can anyone help me , or Do you have any suggestions ?

1 Answer 1

1

just use https://parsleyjs.org/ for form validation on your blade template. Very effective and has a lot of useful API and plugins. Rather than repeating same validation again and again you can make use of this little open source project.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.