Rendering a JSON form using jQuery formbuilder -


i want use jquery formbuilder (http://formbuilder.readthedocs.io/en/latest/) , want render json form generated formbuilder on web page.

can show how can achieve coldfusion?

here sample of json generated formbuilder:

[     {         "type": "date",         "label": "date field",         "classname": "form-control",         "name": "date-1502794115227"     },     {         "type": "button",         "label": "button",         "subtype": "button",         "classname": "btn-default btn",         "name": "button-1502794117421",         "style": "default"     } ] 

how display form on page? not familiar json. ideal if deserialize json , return actual html source.

the json displayed formbuilder not know how json coldfusion structure or variable can use. ideas?

as comments on question suggest, json output that's giving preview of how form structure look.

step 1: save form structure

you need first hook action on 'save' button save structure database. using jquery, following (assuming formbuilder in element attribute id="form-builder"). put in js file loaded in form builder page:

// initialise form builder var fb = $( '#form-builder' ).formbuilder();  // post data script save db $( '.save-template' ).on( 'click', function(){      $.ajax({         url: 'save-form.cfm', // point file create save data         type: 'post',         data: {             formstructure: json.stringify( fb.actions.getdata('json') )         },         success: function( response ){              // got response             console.log( 'response save action: ' + response );          },         error: function( jqxhr ){              // went wrong             console.log( 'error saving form (details below)' );             console.log( jqxhr );          }      });  } 

then in cf, use deserialisejson.

save-form.cfm - tag syntax

<!--- converts json string cf array (not struct - json array of fields) ---> <cfset formstructure = deserializejson( form.formstructure ) /> 

save-form.cfm - script syntax

// converts json string cf array (not struct - json array of fields) formstructure = deserializejson( form.formstructure ); 

then loop through array (again, note formbuilder json output array of fields, not struct) operating wish , insert form structure db (either in json format cut out deserialising , looping or individual fields using relational db work).

step 2: load form user

this lot more complex think - working , ended rewriting whole formrender library better suit our needs.

i'd recommend if you're not familiar kind of approach load in formrender.js (provided form builder installation) , read docs (eh?) that.

if, on other hand, want individually parse fields did, can loop through array, taking each field (which struct) , outputting markup depending on find. i'd show of did, it's library of functions call each other , answer end being way long!

hope helps on way somewhat

jc


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -