285 lines
14 KiB
PHP
Executable File
285 lines
14 KiB
PHP
Executable File
<div use="roughPatch" style="display: none;"></div>
|
|
<div use="setval" style="display: none;" id="setval"><?php echo $newArray?></div>
|
|
<script>
|
|
$( document ).ready(function() {
|
|
$.each($("div[use='dynamic_form']"),function(){
|
|
$(this).attr("processed","N");
|
|
});
|
|
var getvalue = $('#setval').text();
|
|
// setFormByid();
|
|
});
|
|
|
|
function setFormByid_old(){
|
|
console.log("Trigger setFormByid");
|
|
var destdiv = $("div[use='dynamic_form'][processed=N]").first();
|
|
if($(destdiv).length > 0)
|
|
{
|
|
var formid = $(destdiv).attr("template-id");
|
|
//var formid=tempid;
|
|
//alert(formid);
|
|
$.ajax({
|
|
url:"<?php echo base_url(); ?>formbuilder/getFromData",
|
|
type:"GET",
|
|
data:{formid:formid},
|
|
dataType: "text",
|
|
success:function(data){
|
|
console.log("for formid "+formid+" >> ",data);
|
|
//var templateName = "";
|
|
$.ajax({
|
|
url: "<?php echo base_url(); ?>php-form-builder/drag-n-drop-form-builder/ajax/preview.php",
|
|
type: 'POST',
|
|
data: { 'data': data,'<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>' },
|
|
success:function(formoutput){
|
|
|
|
//console.log(formoutput);
|
|
$("div[use='roughPatch']").html(formoutput);
|
|
|
|
$("div[use='roughPatch']").find("script").remove();
|
|
|
|
$("div[use='roughPatch']").find("div.container").find("div").first().remove();
|
|
|
|
$.each($("div[use='roughPatch']").find("div.container").find("form").find("div.form-group"),function(){
|
|
$(destdiv).append($(this).clone());
|
|
});
|
|
|
|
//loaddata(tempid,destdiv);
|
|
|
|
$(destdiv).attr("processed","Y");
|
|
|
|
$("div[use='roughPatch']").empty();
|
|
var abc = $('#setval').text();
|
|
console.log("Moli>>>>>>>>>>>>",abc);
|
|
try{
|
|
// var form_obj_value=JSON.parse($("textarea[name='dynamicFormData']").val());
|
|
|
|
var form_obj_value=JSON.parse(abc);
|
|
// var thisDataSet=form_obj_value[formid];
|
|
var thisDataSet=form_obj_value;
|
|
console.log(".............",thisDataSet);
|
|
|
|
for (var id in thisDataSet) {
|
|
var thiObj=thisDataSet[id];
|
|
|
|
console.log(id);
|
|
|
|
$("input[type=text][name='"+id+"']").val(thiObj);
|
|
$("input[type=date][name='"+id+"']").val(thiObj);
|
|
|
|
$("select[name='"+id+"'] option[value='"+thiObj+"']").prop('selected', true);
|
|
|
|
$("select[name='"+id+"']").show();
|
|
|
|
$("textarea[name='"+id+"']").val(thiObj);
|
|
$("input[type=checkbox][name='"+id+"'][value='"+thiObj+"']").prop( "checked", true );
|
|
$("input[type=radio][name='"+id+"']").prop( "checked", true );
|
|
|
|
|
|
/////old///
|
|
// $("input[type=text][name='"+thiObj.name+"']").val(thiObj.value);
|
|
// $("input[type=date][name='"+thiObj.name+"']").val(thiObj.value);
|
|
|
|
// $("select[name='"+thiObj.name+"'] option[value='"+thiObj.value+"']").prop('selected', true);
|
|
|
|
// $("select[name='"+thiObj.name+"']").show();
|
|
|
|
// $("textarea[name='"+thiObj.name+"']").val(thiObj.value);
|
|
// $("input[type=checkbox][name='"+thiObj.name+"'][value='"+thiObj.value+"']").prop( "checked", true );
|
|
// $("input[type=radio][name='"+thiObj.name+"']").prop( "checked", true );
|
|
|
|
}
|
|
|
|
} catch(e){ console.log(e.message);}
|
|
setFormByid();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
</script>
|
|
<script type="text/javascript">
|
|
function setFormByid(){
|
|
var destdiv=$("div[use='dynamic_form'][processed=N]").first();
|
|
var url='<?=base_url()?>'+'formbuilder/getFromData';
|
|
if($(destdiv).length>0){
|
|
var formid=$(destdiv).attr("template-id");
|
|
// console.log(formid,destdiv.closest('form')[0]);
|
|
$.ajax({
|
|
url:url,
|
|
type:"GET",
|
|
data:{
|
|
formid:formid
|
|
},
|
|
dataType: "text",
|
|
success:function(data){
|
|
drawForm(data,destdiv);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
function drawForm(data,destdiv){
|
|
var url='<?=base_url()?>'+'php-form-builder/drag-n-drop-form-builder/ajax/preview.php';
|
|
$.ajax({
|
|
url: url,
|
|
type: 'POST',
|
|
data: {
|
|
'data': data,
|
|
'<?=$this->security->get_csrf_token_name()?>': '<?=$this->security->get_csrf_hash()?>'
|
|
},
|
|
success:function(formoutput){
|
|
$("div[use='roughPatch']").html(formoutput);
|
|
$("div[use='roughPatch']").find("script").remove();
|
|
$("div[use='roughPatch']").find("div.container").find("div").first().remove();
|
|
$.each($("div[use='roughPatch']").find("div.container").find("form").find("div.form-group"),function(){
|
|
$(destdiv).append($(this).clone());
|
|
});
|
|
$(destdiv).attr("processed","Y");
|
|
$("div[use='roughPatch']").empty();
|
|
var abc=$('#setval').text();
|
|
try{
|
|
var form_obj_value=JSON.parse(abc);
|
|
var thisDataSet=form_obj_value;
|
|
for(var id in thisDataSet){
|
|
var thiObj=thisDataSet[id];
|
|
$("input[type=text][name='"+id+"']").val(thiObj);
|
|
$("input[type=date][name='"+id+"']").val(thiObj);
|
|
$("input[type=time][name='"+id+"']").val(thiObj);
|
|
$("input[type=number][name='"+id+"']").val(thiObj);
|
|
$("input[type=email][name='"+id+"']").val(thiObj);
|
|
$("select[name='"+id+"'] option[value='"+thiObj+"']").prop('selected',true);
|
|
$("select[name='"+id+"']").show();
|
|
$("textarea[name='"+id+"']").val(thiObj);
|
|
var checkbox_id = id+'[]';
|
|
$("input[type=checkbox][name='"+checkbox_id+"'][value='"+thiObj+"']").prop( "checked",true);
|
|
$("input[type=radio][name='"+id+"'][value='"+thiObj+"']").prop( "checked", true );
|
|
}
|
|
}
|
|
catch(e){
|
|
console.log(e.message);
|
|
}
|
|
setFormByid();
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<script type="text/javascript">
|
|
$(document).ready(function(){
|
|
$('#visit-info-tab').closest('.hgfdyevfhjgvshgdv6').trigger('click');
|
|
var trgt=$("#collapseTwentySix");
|
|
loadFormsNew(trgt);
|
|
if($('#annual_in_home_Modal').length>0){
|
|
var annual = $('#annual_in_home_Modal');
|
|
loadFormsNew(annual);
|
|
}
|
|
});
|
|
$(document).on('click','.hgfdyevfhjgvshgdv6',function(){
|
|
var trgt=$($(this).find('a.nav-link').attr('href'));
|
|
loadFormsNew(trgt);
|
|
});
|
|
function loadFormsNew(trgt){
|
|
var destdiv=trgt.find("div[use='dynamic_form'][processed=N]");
|
|
console.log(destdiv.length);
|
|
for(var i=0;i<destdiv.length;i++){
|
|
setFormByidNew(destdiv[i]);
|
|
}
|
|
}
|
|
function setFormByidNew(destdiv){
|
|
var formid=$(destdiv).attr("template-id");
|
|
|
|
var url='<?=base_url()?>'+'formbuilder/getFromData';
|
|
$.ajax({
|
|
async: false,
|
|
url:url,
|
|
type:"GET",
|
|
data:{
|
|
formid:formid
|
|
},
|
|
dataType: "text",
|
|
success:function(data){
|
|
drawFormNew(data,destdiv);
|
|
}
|
|
});
|
|
}
|
|
function drawFormNew(data,destdiv){
|
|
var url='<?=base_url()?>'+'php-form-builder/drag-n-drop-form-builder/ajax/preview.php';
|
|
$.ajax({
|
|
async: false,
|
|
url: url,
|
|
type: 'POST',
|
|
data: {
|
|
'data': data,
|
|
'<?=$this->security->get_csrf_token_name()?>': '<?=$this->security->get_csrf_hash()?>'
|
|
},
|
|
success:function(formoutput){
|
|
$("div[use='roughPatch']").html(formoutput);
|
|
$("div[use='roughPatch']").find("script").remove();
|
|
$("div[use='roughPatch']").find("div.container").find("div").first().remove();
|
|
$.each($("div[use='roughPatch']").find("div.container").find("form").find("div.form-group"),function(){
|
|
$(destdiv).append($(this).clone());
|
|
});
|
|
$(destdiv).attr("processed","Y");
|
|
$("div[use='roughPatch']").empty();
|
|
var abc=$('#setval').text();
|
|
try{
|
|
var form_obj_value=JSON.parse(abc);
|
|
var thisDataSet=form_obj_value;
|
|
for(var id in thisDataSet){
|
|
var thiData=thisDataSet[id];
|
|
thiData=canParseJSON(thiData)?JSON.parse(thiData):thiData;
|
|
if(!Array.isArray(thiData)){
|
|
thiData=[thiData];
|
|
}
|
|
for(var i in thiData){
|
|
var thiObj=''+thiData[i];
|
|
thiObj=(typeof thiObj==='string')?thiObj.replace("'", ""):thiObj;
|
|
$("input[type=text][name='"+id+"']").val(thiObj);
|
|
$("input[type=date][name='"+id+"']").val(thiObj);
|
|
$("input[type=time][name='"+id+"']").val(thiObj);
|
|
$("input[type=number][name='"+id+"']").val(thiObj);
|
|
$("input[type=email][name='"+id+"']").val(thiObj);
|
|
// $("select[name='"+id+"'] option[value='"+thiObj+"']").prop('selected',true);
|
|
$("select[name='"+id+"']").find('option[value="'+thiObj+'"]').prop('selected',true);
|
|
$("select[name='"+id+"']").show();
|
|
$("textarea[name='"+id+"']").val(thiObj);
|
|
var checkbox_id = id+'[]';
|
|
$("input[type=checkbox][name='"+checkbox_id+"'][value='"+thiObj+"']").prop( "checked",true);
|
|
$("input[type=checkbox][name='"+id+"'][value='"+thiObj+"']").prop( "checked",true);
|
|
// $('input[type=checkbox][name="'+checkbox_id+'"][value="'+thiObj+'"]').prop("checked",true);
|
|
$("input[type=radio][name='"+id+"'][value='"+thiObj+"']").prop( "checked", true );
|
|
// $('input[type=radio][name="'+id+'"][value="'+thiObj+'"]').prop("checked",true);
|
|
}
|
|
}
|
|
// for(var id in thisDataSet){
|
|
// var thiObj=thisDataSet[id];
|
|
// $("input[type=text][name='"+id+"']").val(thiObj);
|
|
// $("input[type=date][name='"+id+"']").val(thiObj);
|
|
// $("input[type=time][name='"+id+"']").val(thiObj);
|
|
// $("input[type=number][name='"+id+"']").val(thiObj);
|
|
// $("input[type=email][name='"+id+"']").val(thiObj);
|
|
// // $("select[name='"+id+"'] option[value='"+thiObj+"']").prop('selected',true);
|
|
// $("select[name='"+id+"']").find('option[value="'+thiObj+'"]').prop('selected',true);
|
|
// $("select[name='"+id+"']").show();
|
|
// $("textarea[name='"+id+"']").val(thiObj);
|
|
// var checkbox_id = id+'[]';
|
|
// // $("input[type=checkbox][name='"+checkbox_id+"'][value='"+thiObj+"']").prop( "checked",true);
|
|
// $('input[type=checkbox][name="'+checkbox_id+'"][value="'+thiObj+'"]').prop("checked",true);
|
|
// // $("input[type=radio][name='"+id+"'][value='"+thiObj+"']").prop( "checked", true );
|
|
// $('input[type=radio][name="'+id+'"][value="'+thiObj+'"]').prop("checked",true);
|
|
// }
|
|
}
|
|
catch(e){
|
|
console.log(e.message);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
function canParseJSON(value) {
|
|
try {
|
|
JSON.parse(value);
|
|
return true;
|
|
} catch (error) {
|
|
return false;
|
|
}
|
|
}
|
|
</script>
|