samedi 9 janvier 2016

How to add csrf_field() into jqgrid on laravel 5.1

this is simple question but i'm new in laravel. So, i have project that use jqgrid for form processing but, i don't know how to add {!! csrf_field() !!} into jqgrid for processing form to router or controller.

Here is my jqgrid code:

 <script>
 $.jgrid.defaults.width = 700;
 $.jgrid.defaults.responsive = true;
 $.jgrid.defaults.styleUI = 'Bootstrap';

 $(document).ready(function () {
 var template = "<div style='margin-left:20px;'><div> id <sup>*</sup>:</div><div> {id} </div>";
 template += "<div> vendor_id: </div><div>{vendor_id} </div>";
 template += "<div> vendor_name: </div><div>{vendor_name} </div>";
 template += "<div> address: </div><div>{address} </div>";
 template += "<div> contact_no:</div><div> {contact_no} </div>";
 template += "<div> email:</div><div> {email} </div>";
 template += "<div> fax_no:</div><div> {fax_no} </div>";
 template += "<div> remark:</div><div> {remark} </div>";
 template += "<hr style='width:100%;'/>";
 template += "<div> {sData} {cData}  </div></div>";

           $("#jqGrid").jqGrid({
           url: 'http://localhost:9000/home/getData',
           editurl: 'http://localhost:9000/home/vendor/save',
           datatype: "json",
           colModel: [
                       {label: 'Id', name: 'id', width: 50, key: true, editable: true, editrules :
                       { required: true }},
                       {label: 'Vendor Id', name: 'vendor_id', width: 140, editable: true },
                       {label: 'Contract Id ', name: 'contract_id', width: 140, editable: true }, //must set editable to true if you want to make the field editable
                       {label : 'Vendor Name', name: 'vendor_name', width: 150, editable: true },
                       {label: 'Address', name: 'address', width: 190, editable: true },
                       {label: 'Kontak No', name: 'contact_no', width: 130, editable: true },
                       {label: 'Email', name: 'email', width: 140, editable: true },
                       {label: 'Fax No', name: 'fax_no', width: 140, editable: true },
                       {label: 'Remark', name: 'remark', width: 140, editable: true }

                     ],
           mtype:'GET',
           sortname: 'id',
           sortorder : 'asc',
           caption: "Detail Vendor",
           loadonce: true,
           viewrecords: true,
           width: 1000,
           height: 500,
           rowNum: 10,
           pager: "#jqGridPager"
           });



           $('#jqGrid').navGrid('#jqGridPager',
            //the buttons to appear on the toolbar of the grid
           { edit: true,
             add: true,
             del: true,
             search: true,
             refresh: true,
             view: true,
             position: "left",
             cloneToTop: true,
           },

           {
           editCaption: "Edit Data",
           template: template,
               errorTextFormat: function (data) {
                   return 'Error: ' + data.responseText
               }
           },
            //options for the Add Dialog
           {
           template: template,
               errorTextFormat: function (data) {
                   return 'Error: ' + data.responseText
               }
           },
            //options for the Delete Dailog
           {
               errorTextFormat: function (data) {
                   return 'Error: ' + data.responseText
               }
           });
   });

=======================================================

And this is error when I submit to processing form

Error when submit the button

As the above code, where is i must take {!! csrf_field() !!}. Thank you...



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire