lundi 30 avril 2018

Insert Values from Nested Dynamic Input fields into Database in PHP

I'm new to PHP and struggling with one problem. I have nested dynamic input fields like so:

$(add_subservice).click(function(e){ 
e.preventDefault();
y=0;
if(x < max_fields){
    x++; 
    $(wrapper).append('<div style="margin-left:5%"><input type="text" 
name="subservice['+x+'][]" placeholder="Enter Sub Service"/><input 
type="text" name="subserviceprice['+ x +'][]" placeholder="Enter Sub Service 
Price"/><a href="#" class="remove_field">Remove</a><div style="margin- 
left:5%"><button type="button" class="add_subsubservice" style="margin- 
right: 20%">Add More Sub-Sub Service</button></div>'); 


    $(".add_subsubservice").click(function(e){ 
        e.preventDefault();
        if(y < max_fields){
            y++; //text box increment
            $(wrapper).append('<div style="margin-left:8%"><input 
 type="text" name="subsubservice['+ x +'][]" placeholder="Enter Sub-Sub 
 Service"/><a href="#" class="remove_field_ss">Remove</a></div>');
        }
    });

    $(wrapper).on("click",".remove_field_ss", function(e){ //user click on 
  remove text
        e.preventDefault(); $(this).parent('div').remove(); y--;
    })
}
});

Now I wish to get the values from both the input fields in an array in the following manner"

services =>{
    SubService1 =>{
              0: SubSubService11
              1: SubSubService12
              2: SubSubService13
    }
    SubService2 =>{
              0: SubSubService21
              1: SubSubService22
              2: SubSubService23
    }
    .
    .
    .
    SubServiceN: { ... }
}

Would the above format of the array help me insert values in the Database effectively or is there any alternate way?

I will really appreciate any help one can provide. Thanks.




Aucun commentaire:

Enregistrer un commentaire