mardi 2 juillet 2019

How to get single value from brand_id=2&hdbrand_id=&pcat_id=38&pcat_name=SHOES. in PHP

I have value from posted data. And its formed in

brand_id=2&hdbrand_id=&pcat_id=38&pcat_name=SHOES.

I try to separate it with array explode, but it will be generated and i must iterate it as a key value. what i want to do is get every single variable in that formed value. Do you mind to help me out?

here is my complete code

blade view

<div class="content splite">
<div class="splite-item">
    <div class="bag-white">
        <div class="title-content"><i class="fa fa-file-text-o"></i>CREATE PRODUCT CATEGORIES FORM</div>
        <!-- <form class="form-main" action="" method="post"> -->
        <form class="form-main" id="formCat">
            <div class="field radio" data-title="Brands">
              @foreach($dataBrands as $brands)
                    <input type="radio" id="radio-" name="brand_id" value=""  >
                    <label for="radio-"></label>     
                @endforeach
                <input type="hidden" name="hdbrand_id" >
                <input type="hidden" id="pcat_id" name="pcat_id" value="" >
            </div>
            <div class="field" data-title="Nama Kategori">
            <input type="text" id="pcat_name" name="pcat_name" value="" autofocus>
            </div>
            <div class="field" data-title="Action">
                <button id="btnSave" type="button" class="but-main">add</button>
                <a href="/product-categories" class="but-main"><i class="fa fa-times"></i>Batal</a>
            </div>
        </form>
    </div>
</div>

Jquery

$('#btnSave').click(function(){
var form = $('#formCat').serialize();
var id = $('#pcat_id').val();
var url = "";
url = url.replace(':id',id);
$.ajax({
    type:'POST',
    headers: {
        'X-CSRF-TOKEN' : ""
    },
    url: url,
    data: {form:form, "_method":"PUT"},
    success:function(data){

        console.log(data);
    },
    error:function(data){
      console.log(data);

    }

});

});

Controller

    public function update($id){

    $category = Input::get('form');
    return $category;

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire