php - How to store dynamically generated form input field and its data in database -


this how html field stor in database using ajax.the problem when print these form fields database, don't know how print value of these fields because form fields stor html in database.i need print value of dynamically generated form input field update.

     $("#save_field").on('submit',function (e) {                 var field = {};                 var options = [];                 $.each($(this).serializearray(), function (i, f) {                     field[f.name] = f.value;                     if("options" == f.name.slice(0,7)){                         options.push(f.value);                     }                 });                 switch(field['type']){                     case 'text':                           element = '<div class="form-group">'+                                 '<label class="col-md-3 control-label">'+field['label']+'</label>'+                                 '<div class="col-md-6">'+                                 '<input type="text"  name="custom_text[]" value="'+ field['default_value'] +'" class="form-control" placeholder="">'+                                 '</div>'+                                 '<input type="hidden" name="type" value="text">'+                                 '</div>';                         break;                     case 'select':                          element =                                 '<div class="form-group">'+                                 '<label class="col-md-3 control-label">'+field['label']+'</label>'+                                 '<div class="col-md-6">'+                                 '<select id="custom_select" class="bs-select form-control" name="custom_select[]">';                                  for(index = 0; options.length - 1 > index; index += 2) {                                      element = element.concat('<option value="'+ options[index+1] +'">'+ options[index] +'</option>');                                  };                                var x = '</select>'+                                 '</div>'+                                 '<input type="hidden" name="type" value="select">'+                                 '</div>';                         element = element.concat(x);                         break;                     case 'date':                         element =                             '<div class="form-group">'+                                 '<label class="control-label col-md-3">'+field['label']+'</label>'+                                 '<div class="col-md-6">'+                                     '<div class="input-group input-large date date-picker" data-date-format="dd-mm-yyyy" >'+                                         '<input type="text" class="form-control" name="custom_date[]" readonly>'+                                             '<span class="input-group-btn">'+                                                 '<button class="btn default" type="button">'+                                                     '<i class="fa fa-calendar"></i>'+                                                 '</button>'+                                             '</span>'+                                     '</div>'+                                 '</div>'+                             '<input type="hidden" name="type" value="date">'+                             '</div>';                     break;                 }                  values = $(this).serialize();                 values += "&element=" + encodeuricomponent(element);                 var request = $.ajax({                     url: "{{'store_domain_custom_field'}}",                     method: "post",                     data:values,                 });                  request.done(function(data) { //                    field = json.parse(data);                     $("#responsive").modal('hide');                     $('#save_field')[0].reset();                     $("#custom").fadeout(800, function(){                         $("#custom").append(element).fadein().delay(1000);                     }); //                    location.reload();                 });                  request.fail(function(jqxhr, textstatus) {                 });                 e.preventdefault();             }); 

this how store fields printed after storing in database.

<div id="custom">    @if(isset($fields) && !empty($fields))        @foreach($fields $field)             {!! html_entity_decode($field->element) !!}        @endforeach    @endif </div> 

this function store form fields in database using laravel frame work

public function storedomaincustomfield(request $request){          if ($request->ismethod('post') && $request->has('process_domain_id')) {              $field = new inputfield();             $field->label = $request->label;             $field->table_name = 'process_domain';             $field->refrence_id = $request->process_domain_id;             $field->type = $request->type;             $field->tool_tip = $request->tool_tip;             $field->default_value = $request->default_value;             $field->element = $request->element;             $select_options = array();             $options_values = array();             if($request->has('options') && $request->type == 'select'){                  foreach($request->options $option){                      $select_options[] = $option['opt'];                     $options_values[] = $option['val'];                 }                  $field->options = implode(',' ,$select_options);                 $field->option_values = implode(',' ,$options_values);             }              if($field->save()){                  return response(json_encode($field->toarray()), 200)->header('content-type', 'text/plain');             }              return response('error', 500)->header('content-type', 'text/plain');          }       } 


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -