php - How to insert multiple form(bootstrap modal) values into database using ajax post request in laravel? -
i'm having 2 bootstrap modals , trying insert modal values 2 different tables on "save button" click respectively corresponding modals.
<!--1st modal--> <div class="price"> <form name="formprice"> <div class="modal fade" id="price"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">close</span> </button> <h4 class="modal-title">selling information</h4> </div> <div class="modal-body" id="modal-content"> <div class="row"> <div class="col-sm-12"> <b>listing information</b> <h6>seller sku id <a href="#" class='my-tool-tip' data-toggle="tooltip" data-placement="right" title="unique identifier listings"> <span class="glyphicon glyphicon-info-sign" style="color: #337ab7"></span> </a></h6> <input type="text" name="skuid" id="skuvalue" class="pricevalue"/> </div> </div> <br/> <br/> <div class="row"> <div class="col-sm-12"> <b>status details</b> <h6>listing status <a href="#" class='my-tool-tip' data-toggle="tooltip" data-placement="right" title="inactive listings not available buyers on flipkart"> <span class="glyphicon glyphicon-info-sign" style="color:#337ab7"></span> </a></h6> <select id="dropdownid" name="listingstatus"> <option selected disabled>--choose here--</option> <option value="active">active</option> <option value="inactive">inactive</option> </select> </div> </div> <br/> <br/> <div class="row"> <b>price details</b> <div class="col-sm-12"> <div class="col-sm-6"> <h6>mrp <a href="#" class='my-tool-tip' data-toggle="tooltip" data-placement="right" title="maximum retail price of product"> <span class="glyphicon glyphicon-info-sign" style="color: #337ab7"></span> </a></h6> <input type="text" name="mrp" id="mrpvalue" class="check-fill"/> </div> <div class="col-sm-6"> <h6>your selling price <a href="#" class='my-tool-tip' data-toggle="tooltip" data-placement="right" title="price @ want sell listing"> <span class="glyphicon glyphicon-info-sign" style="color:#337ab7"></span> </a></h6> <input type="text" name="selprice" id="selpricevalue" class="check-fill"/> </div> </div> </div> <br/> <br/> <div class="row"> <b>inventory details</b> <div class="col-sm-12"> <div class="col-sm-6"> <h6>fulfilment <a href="#" class='my-tool-tip' data-toggle="tooltip" data-placement="right" title="fullfilment of fa listings managed flipkart "> <span class="glyphicon glyphicon-info-sign" style="color: #337ab7"></span> </a></h6> <select id="5" name="fulfillment"> <option selected disabled>choose here</option> <option value="seller">seller</option> </select> <br/> <h6>procurement sla <a href="#" class='my-tool-tip' data-toggle="tooltip" data-placement="right" title="time required keep product ready dispatch"> <span class="glyphicon glyphicon-info-sign" style="color:#337ab7"></span> </a></h6> <input type="text" name="sla" class="check-fill"/>days <br/> <h6>stock available buyers <a href="#" class='my-tool-tip' data-toggle="tooltip" data-placement="right" title="number of items available cutomer buy after detecting pending orders" > <span class="glyphicon glyphicon-info-sign" style="color: #337ab7"></span> </a></h6> <input type="text" name="available" readonly/> </div> <div class="col-sm-6"> <h6>procurement type <a href="#" class='my-tool-tip' data-toggle="tooltip" data-placement="right" title="information on how inventory procured seller fulfill order"> <span class="glyphicon glyphicon-info-sign" style="color:#337ab7"></span> </a></h6> <select name="procurementtype"> <option selected disabled>--choose here--</option> <option value="instock">instock</option> </select> <br/> <h6>stock <a href="#" class='my-tool-tip' data-toggle="tooltip" data-placement="right" title="number of items have in stock"> <span class="glyphicon glyphicon-info-sign" style="color: #337ab7"></span> </a></h6> <input type="text" name="stock" /> <br/> </div> </div> </div> <br/> <br/> <div class="row"> <b>delivery charge customer</b> <div class="col-sm-12"> <div class="col-sm-4"> <h6>local delivery charge <a href="#" class='my-tool-tip' data-toggle="tooltip" data-placement="right" title="delivery charge want charge buyer in same city listings not flipkart assured"> <span class="glyphicon glyphicon-info-sign" style="color:#337ab7"></span> </a></h6> <input type="text" name="local" /> </div> <div class="col-sm-4"> <h6>zonal delivery charge <a href="#" class='my-tool-tip' data-toggle="tooltip" data-placement="right" title="delivery charge want charge buyer in same zone listings not flipkart assured"> <span class="glyphicon glyphicon-info-sign" style="color: #337ab7"></span> </a></h6> <input type="text" name="zonal" /> </div> <div class="col-sm-4"> <h6>national delivery charge <a href="#" class='my-tool-tip' data-toggle="tooltip" data-placement="right" title="delivery charge want charge buyer outside zone listings not flipkart assured"> <span class="glyphicon glyphicon-info-sign" style="color:#337ab7"></span> </a></h6> <input type="text" name="national" /> </div> </div> </div> <br/> <br/> <div class="row"> <b>packaging details</b> <div class="col-sm-12"> <div class="col-sm-3"> <h6>package weight <a href="#" class='my-tool-tip' data-toggle="tooltip" data-placement="right" title="weight of final package in kgs"> <span class="glyphicon glyphicon-info-sign" style="color: #337ab7"></span> </a></h6> <input type="text" name="weight" />kgs </div> <div class="col-sm-3"> <h6>package length <a href="#" class='my-tool-tip' data-toggle="tooltip" data-placement="right" title="length of final package in cms"> <span class="glyphicon glyphicon-info-sign" style="color:#337ab7"></span> </a></h6> <input type="text" name="length" />cms </div> <div class="col-sm-3"> <h6>package breadth <a href="#" class='my-tool-tip' data-toggle="tooltip" data-placement="right" title="breadth of final package in cms"> <span class="glyphicon glyphicon-info-sign" style="color: #337ab7"></span> </a></h6> <input type="text" name="breadth" />cms </div> <div class="col-sm-3"> <h6>package height <a href="#" class='my-tool-tip' data-toggle="tooltip" data-placement="right" title="height of final package in cms"> <span class="glyphicon glyphicon-info-sign" style="color:#337ab7"></span> </a></h6> <input type="text" name="height" />cms </div> </div> </div> <br/> <br/> <div class="row"> <div class="col-sm-12"> <b>tax details</b> <h6>hsn <a href="#" class='my-tool-tip' data-toggle="tooltip" data-placement="right" title="code of product determining applicable tax rates"> <span class="glyphicon glyphicon-info-sign" style="color: #337ab7"></span> </a></h6> <input type="text" name="hsn" /> <a href="#">find relevant hsn codes</a> </div> </div> <br/> <br/> <input type="submit" id="pricesave" class="save" value="save" style="border-radius: 8px; padding: 5px 15px; " > </form> </div> <div class="modal-footer"> <button type="button" class="btn btn-info" data-dismiss="modal">close</button> <!--<button type="submit" id="pricesave" class="save" style="border-radius: 8px; padding: 5px 15px; display:none;">save</button>--> </div> </div> <!-- /.modal-content --> </div> <!-- /.modal-dialog --> </div> </div> <!--2nd modal--> <div class="description"> <form name="formdescription"> <div class="modal fade" id="description"> <div class="modal-dialog"> <!-- modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">product description</h4> </div> <div class="modal-body" id="modal-content"> <div class="row"> <div class="col-sm-12"> <b>title attributes</b> <h6>model name </h6> <input type="text" name="mname" placeholder="ex:" id="mnamevalue"/> </div> </div> <br/> <br/> <div class="row"> <b>others</b> <div class="col-sm-12"> <div class="col-sm-4"> <h6>height <a href="#" class='my-tool-tip' data-toggle="tooltip" data-placement="right" title="height refers measurement top base or head foot.possible values 34,36 etc."> <span class="glyphicon glyphicon-info-sign" style="color: #337ab7"></span> </a></h6> <input type="text" name="height" placeholder="ex:34"> <br/> <br/> <h6>width</h6> <input type="text" name="width" placeholder="ex:23"> <br/> <br/> <h6>battery type</h6> <select id="btypevalue" name="batterytype"> <option selected disabled>--select one--</option> <option value="no batteries">no batteries</option> <option value="aa">aa</option> <option value="aaa">aaa</option> <option value="lithium">lithium</option> </select> <br/> <br/> <h6>colour</h6> <select id="colourvalue" name="colour"> <option selected disabled>--select one--</option> <option value="instock">instock</option> </select> <br/> <br/> <h6>number of batteries</h6> <select name="batterynos"> <option selected disabled>--select one--</option> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> <br/> <br/> <h6>rechargable</h6> <select id="rvalue" name="rechargable"> <option selected disabled>--select one--</option> <option value="yes">yes</option> <option value="no">no</option> </select> <br/> <br/> </div> <div class="col-sm-4"> <h6>weight </h6> <input type="text" name="weight" placeholder="ex:500"> <br/> <br/> <h6>type</h6> <select name="type"> <option selected disabled>--select one--</option> <option value="no batteries">no batteries</option> <option value="aa">aa</option> <option value="aaa">aaa</option> <option value="lithium">lithium</option> </select> <br/> <br/> <div id=container> <div class="addpack"> <h6>sales package </h6> <div> <input type="text" name="package" placeholder="ex:34" id="package" class="packageclass"> <input type="submit" value="+" class="addnext"></div> </div> </div> <br/> <br/> <div id="container"> <div class="material1"> <h6>material </h6> <div> <select class="materialclass" name="material"> <option selected disabled>--select one--</option> <option value="no batteries">no batteries</option> <option value="aa">aa</option> <option value="aaa">aaa</option> <option value="lithium">lithium</option> </select> <input type="submit" value="+" class="material"></div> </div> </div> <br/> <br/> <h6>minimum age</h6> <input type="text" name="minage" placeholder="ex:36"> <br/> <br/> </div> <div class="col-sm-4"> <h6>depth</h6> <input type="text" name="depth" placeholder="ex:12"> <br/> <br/> <div id=container> <div class="add1"> <h6>character</h6> <div> <input type="text" name="character" placeholder="ex:"> <input type="submit" value="+" class="add"></div> </div> </div> <br/> <br/> <div id=container> <div class="select1"> <h6>skillset</h6> <div> <select name="skillset"> <option selected disabled>--select one--</option> <option value="no batteries">no batteries</option> <option value="aa">aa</option> <option value="aaa">aaa</option> <option value="lithium">lithium</option> </select> <input type="submit" value="+" class="select"></div> </div> </div> <br/> <br/> <h6>maximum age</h6> <input type="text" name="maxage" placeholder="ex:36"> <br/> <br/> <h6>battery operated</h6> <select name="batteryoperated"> <option selected disabled>--select one--</option> <option value="yes">yes</option> <option value="no">no</option> </select> </div> </div> </div> <br/> <br/> <input type="submit" class="save" id="descsave" style="border-radius: 8px; padding: 5px 15px;" value="save"> </form> </div> <div class="modal-footer"> <button type="button" class="btn btn-info" data-dismiss="modal">cancel</button> <!-- <button type="button" class="save" id="descsave" style="border-radius: 8px; padding: 5px 15px; display:none;">save</button>--> </div> </div> </div> </div> </div>
those 2 bootstrap modals.
script code:
<script type="text/javascript"> $(document).ready(function () { $.ajaxsetup({ headers: { 'x-csrf-token': $('meta[name="csrf-token"]').attr('content') } }); $("#pricesave").click(function(e){ e.preventdefault(); //var form1=$("#formprice").serialize(); var data = $('form').serialize(); $.ajax({ url:'addpricedetails/{{$dataid}}', type: "post", data: data, datatype: 'json', success: function(response) { $("#skuid").append(response.skuid); $("#mrp").append(response.mrp); $("#lstatus").append(response.listingstatus); $("#selprice").append(response.sellingprice); //alert(response.skuid); } }); }); $("#descsave").click(function(e){ e.preventdefault(); var form2=$("#formdescription").serialize(); //var data = $('form').serialize(); $.ajax({ url:'addpricedetails/{{$dataid}}', type: "post", data: form2, datatype: 'json', success: function(response) { alert(response); } }); }); }); </script>
this script code have tried insert 2 modal values db using ajax post request.but first form gets added.and not second modal values.
laravel route:
route::post('addpricedetails/{dataid}','pricedetails@addpricedetails');
controller code:
public function addpricedetails(request $dataid) { $priceinfo = new pricemodel ; $priceinfo->devicecategoryid=$dataid; $priceinfo->productid=$this->getproductid(); $priceinfo->skuid=$formprice->input('skuid'); $priceinfo->listingstatus =$formprice->input('listingstatus'); $priceinfo->mrp =$formprice->input('mrp'); $priceinfo->sellingprice=$formprice->input('selprice'); $priceinfo->fulfillmentby =$formprice->input('fulfillment'); $priceinfo->procurementtype =$formprice->input('procurementtype'); $priceinfo->procurementsla =$formprice->input('sla'); $priceinfo->stock =$formprice->input('stock'); $priceinfo->localdelcharge =$formprice->input('local'); $priceinfo->zonaldelcharge =$formprice->input('zonal'); $priceinfo->nationaldelcharge=$formprice->input('national'); $priceinfo->packweight =$formprice->input('weight'); $priceinfo->packlength =$formprice->input('length'); $priceinfo->packbreadth =$formprice->input('breadth'); $priceinfo->packheight =$formprice->input('height'); $priceinfo->hsn =$formprice->input('hsn'); $priceinfo->save(); $description=new descriptionmodel; $description->devicecategoryid=$dataid; $description->productdescriptionid=$this->getproductdescriptionid(); $description->modelname=$formdescription->input('mname'); $description->height=$formdescription->input('height'); $description->weight=$formdescription->input('weight'); $description->depth=$formdescription->input('depth'); $description->width =$formdescription->input('width'); $description->type =$formdescription->input('type'); $description->character=$formdescription->input('character'); $description->batterytype=$formdescription->input('batterytype'); $description->salespackage =$formdescription->input('package'); $description->skillset =$formdescription->input('skillset'); $description->colour=$formdescription->input('colour'); $description->material =$formdescription->input('material'); $description->maxage=$formdescription->input('maxage'); $description->minage =$formdescription->input('minage'); $description->batterynos =$formdescription->input('batterynos'); $description->batteryoperated=$formdescription- >input('batteryoperated'); $description->rechargable=$formdescription->input('rechargable'); $description->save(); return response()->json([ 'skuid' => $priceinfo->skuid, 'listingstatus' => $priceinfo->listingstatus, 'mrp' => $priceinfo->mrp, 'sellingprice' => $priceinfo->sellingprice // ... other fields want return ]); }
this controller code have tried.
Comments
Post a Comment