此处它仅询问第一个表的验证。我想验证所有三个表 我有一个窗体,使基于选择复选框的控制器ajax调用。laravel中的Ajax请求验证
Ajax显示一个在控制器中进行验证的表格。
当我选择三个复选框并点击提交按钮时,ajax检索到三张表。我的问题是,当点击提交按钮而没有填写表格细节时,它只会要求验证第一个表格。
我想显示ajax提取的所有表的验证。
我的形式是:
{!! Form::open(array('class' => 'form-horizontal', 'id' => 'lawpopupformdata', 'files' => true)) !!}
AJAX代码:
$("#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
{
$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.='
$res_div.='
'.$law_details->lm_id.' ('.$law_details->law_name.')
*
*
';foreach($sublaw_details as $sublawdetails)
{
if (in_array($sublawdetails->sublaw_id, $sublawdata))
{
$res_div.='
Start Date: End Date: '.$sublawdetails->lms_id.' ('.$sublawdetails->sub_law_name.')';
}
}
$res_div.='
';}
}
}
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);
}
2017-08-16
Deb