>

여기서 첫 번째 테이블에 대해서만 유효성 검사를 요청합니다. 세 테이블 모두에 대한 유효성 검사를 원합니다 확인란 선택을 기반으로 컨트롤러에 아약스 호출을하는 양식이 있습니다 .

Ajax는 컨트롤러에서 검증 된 테이블을 표시합니다.

세 개의 확인란을 선택하고 제출 버튼을 누르면 ajax가 세 개의 테이블을 검색합니다. 내 문제는 테이블 세부 사항을 채우지 않고 제출 버튼을 클릭하면 첫 번째 테이블에 대해서만 유효성 검사를 요청하는 것입니다.

아약스가 가져온 모든 테이블에 대한 유효성 검사를 보여주고 싶습니다.

내 양식은 :

{!! Form::open(array('class' => 'form-horizontal', 'id' => 'lawpopupformdata', 'files' => true)) !!}
    <div class="modal fade" id="lawpopupdata" tabindex="-1" role="basic" aria-hidden="false">
        <div class="modal-dialog modal-dialoglaws">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Add Law(s)</h4>
                </div>
                <div class="modal-body modal-bodylaws">
                    <input type="hidden" name="company_id" value="{{$company_master->id}}">
                    @foreach ($laws as $law)
                        <?php
                        $sublaws = DB::table('tbl_law_sub_master')->where('lm_id', $law->id)->select('*')->get(); ?>
                        <ul style="list-style:none;">
                            <li>
                                <input type="checkbox" name="law_type_id[]" id="law_type_id{{ $law->id }}" class="delclass" value="{{ $law->id }}" reldeltype="{{ $law->id }}" />
                                <strong>{{ $law->lm_id }} ( {{ $law->law_name }} )</strong>
                                <ul style="list-style:none;">
                                    @foreach ($sublaws as $sublaw)
                                        <li>
                                            <input type="checkbox" name="law_sub_type_id[]" id="law_sub_type_id{{$sublaw->id}}" value="{{$sublaw->id}}" class="delsubclass" reldeltype="{{ $law->id }}" reldelsubtype="{{$sublaw->id}}" />
                                            {{ $sublaw->lms_id }} ( {{ $sublaw->sub_law_name }} )</li>
                                    @endforeach
                                </ul>
                            </li>
                        </ul>
                    @endforeach </div>
                <div class="modal-footer">
                    <input type="submit" value="Submit" class="btn green">
                    <input type="button" value="Cancel" class="btn red" data-dismiss="modal" aria-hidden="true">
                    <input type="reset" value="Clear" class="btn blue">
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    </form> 

아약스 코드 :

$("#lawpopupformdata").submit(function(event){
            var data_id = $(this).data('id');
            var row_id=$("#row_id").val();
            var start_date = $("#company_start_date").val();
            event.preventDefault();
            var formData = new FormData($(this)[0]);
            $.ajax({
                url: "{{ URL::to('admin/postlawsdata') }}" + '?start_date=' + start_date,
                type: 'POST',
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                dataType: "json",
                success: function (returndata) {
                    var res_sublaw_content=returndata.law_info;
                    var res_sublaw_content1=returndata.law_info;
                    var res_validate_laws = returndata.validate_laws;
                    var res_sub_law_count = returndata.sub_law_count;

                    if(res_sub_law_count==0)
                    {
                        bootbox.alert("Please Select Atleast One Law");
                        return false;
                    }
                    else
                    {
                        document.getElementById("sublaws_content").innerHTML = "";
                        $('#sublaws_content').append(res_sublaw_content);
                        $('#sublaws_content1').append(res_sublaw_content1);
                        $('#laws_data1').val(res_sub_law_count);
                        $('.locationparentsd').bind('change', function(event)
                        {
                            parent_loc_sd = $(this).val();
                            var loc_att_law_id = $(this).attr('att_law_id');
                            var loc_sd_name = '.dynamiclocationparentsd'+loc_att_law_id;
                            $(loc_sd_name).val(parent_loc_sd);
                        });
                        $('.date-picker').datepicker({
                            todayBtn: "linked",
                            autoclose: true,
                            format: 'dd-mm-yyyy'
                        });
                        $('#lawpopupdata').modal('hide');
                        $('#save').show();
                        return false;
                    }
                }
            });

내 컨트롤러 기능 :

public function postlawsdata()
    {
        $lawdata=Input::get('law_type_id');
        $sublawdata=Input::get('law_sub_type_id');
        $start_date = Input::get('start_date');
//        $law_date=Input::get('company_start_date');
        $res_div='';
        $sub_law_count=count($sublawdata);
        $validate_laws='';
        if(count($sublawdata)>0)
        {
            for($i=0;$i<count($lawdata);$i++)
            {
                $law_details = DB::table('tbl_law_master')->where('id', $lawdata[$i])->select('tbl_law_master.id as law_id', 'tbl_law_master.lm_id', 'tbl_law_master.law_name')->first();
                $sublaw_details = DB::table('tbl_law_sub_master')
                    ->where('tbl_law_sub_master.lm_id', $lawdata[$i])
                    ->whereNull('tbl_law_sub_master.deleted_at')
                    ->select('tbl_law_sub_master.id as sublaw_id', 'tbl_law_sub_master.sub_law_name','tbl_law_sub_master.lms_id')->get();

                if(count($sublaw_details)>0)
                {
                    $res_div.='<table width="100%" border="0"  class="table table-striped table-bordered table-hover">';
                    $res_div.='<tr>
                                    <td colspan="2" rowspan="2">    
                                        <strong>'.$law_details->lm_id.' ('.$law_details->law_name.')</strong>
                                    </td>
                                    <td >
                                        <span class="required" aria-required="true">* </span><input type="text" value="'.$start_date.'" placeholder="DD-MM-YYYY (Start Date)" name="law_start_date[]" id="law_start_date" att_law_id="'.$lawdata[$i].'"  class="date-picker required locationformstyle locationparentsd dynamiclocationparentsd'.$lawdata[$i].'">
</td></tr><tr><td>
                                        <span class="required" aria-required="true">* </span><input type="text" placeholder="Law Registration No." name="law_reg_no" id="law_reg_no" class="locationformstyle required">
                                    </td>
                                    </tr>';
                    foreach($sublaw_details as $sublawdetails)
                    {
                        if (in_array($sublawdetails->sublaw_id, $sublawdata))
                        {
                            $res_div.='<tr>
            <td width="220">Start Date: <input type="text" name="sub_law_start_date[]" placeholder="DD-MM-YYYY" onfocus="this.blur()" class="locationformstyle date-picker dynamiclocationparentsd'.$lawdata[$i].'" att_law_id="'.$lawdata[$i].'"> </td>
            <td width="220">End Date: <input type="text"  name="sub_law_end_date[]" placeholder="DD-MM-YYYY" onfocus="this.blur()" class="locationformstyle date-picker"></td>
            <td align="left"><strong>'.$sublawdetails->lms_id.' ('.$sublawdetails->sub_law_name.')</strong>
            <input type="hidden" class="locationformstyle" name="company_sub_laws[]" value="'.$sublawdetails->sublaw_id.'">
            </td>
            </tr>
            ';
                        }
                    }
                    $res_div.='</table>';
                }
            }
        }
        else
        {
            $validate_laws='Please Select Atleast One Law';
        }
        $data=array(
            'law_info'=>$res_div,
            'validate_laws'=>$validate_laws,
            'sub_law_count'=>$sub_law_count
        );
        return json_encode($data);
    }

  • 답변 # 1

    public function postlawsdata()
    
    

    로 변경

    public function postlawsdata(Request $request)
    
    

    이걸 추가

    $this->validate($request,[
       //your validation
    ]);
    
    

관련 자료

  • 이전 node.js - URLSearchParams가 Angular의 get/post에서 노드 서버에 비어 있습니다
  • 다음 android - jsonexception - javalangstring 유형의 값 <!-? php를 jsonobject로 변환 할 수 없습니다