Comments (18)
+1
Much like @dmitri-wm I also discovered https://github.com/dobtco/formbuilder/ but it looks to be abandoned, so I have a preference to invest in a repo that is more actively developed, like yours @kevinchappell, but the JSON export is crucial for me.
from formbuilder.
I'm parsing the XML with PHP and storing it in MySQL. I use the following code:
$form_data = $_POST['form_data'];
$xml = simplexml_load_string($form_data);
$result = [];
if (isset($xml->fields) and isset($xml->fields->field)) { // make sure the form is not empty !
foreach ($xml->fields->field as $record) { // loop through every field
$array = (array)$record; // covert it to an array
$record = current($array); // get the field
$record['options'] = next($array); //additional options, needed for radio buttons, select lists...etc
$result[] = $record;
}
}
return $result;
The result would be an array that you can loop through and store every field in the database. Like this
If you want to convert the XML to JSON, using PHP you can, until the plugin can support exporting directly.
$xml = simplexml_load_string($form_data);
$result = [];
$json = json_encode($xml)
My site is using it here
from formbuilder.
I have tried all the PHP functions mentioned above to parse XML to JSON but none of them turned out a success.
As most of above PHP code uses simplexml_load_string which returns a set of XML objects which is not very easy to parse and it become worse when you need to parse options of radios, select and checkbox. print_r and var_dump do not give full picture of the object tree you got from simplexml_load_string.
Finally I have decide to convert XML to JSON on client side and then simply post the JSON only.
I have used below library from @abdmob for conversion to json.
https://github.com/abdmob/x2js
var x2js = new X2JS();
var xml_str = fbTemplate.value;
var form_json = x2js.xml_str2json(xml_str);
form_json = JSON.stringify(form_json["form-template"]["fields"]["field"]);
from formbuilder.
Hey guys, we created a quick function for it 😌
function fn_parse_form_data( $xml ) {
$fields = array();
$xml = simplexml_load_string( $xml );
$xml = $xml->fields;
if( isset( $xml->field ) ) {
foreach( $xml->children() as $field ) {
$name = (string) $field['name'];
$fields[$name] = array();
foreach( $field->attributes() as $k => $v ) {
$fields[$name][$k] = (string) $v;
}
}
}
return $fields;
}
Example usage:
fn_parse_form_data( '<form-template><fields><field class="form-control text-input" label="Your name" name="text-1462909445840" placeholder="Your name" type="text" subtype="text"></field><field class="form-control text-area" label="Your message" name="textarea-1462882789673" placeholder="Enter your message" type="textarea"></field></fields></form-template>' );
It should return:
Array
(
[text-1462909445840] => Array
(
[class] => form-control text-input
[label] => Your name
[name] => text-1462909445840
[placeholder] => Your name
[type] => text
[subtype] => text
)
[textarea-1462882789673] => Array
(
[class] => form-control text-area
[label] => Your message
[name] => textarea-1462882789673
[placeholder] => Enter your message
[type] => textarea
)
)
Best 😉
from formbuilder.
+1
would be great if I could add this to my php web app.
I could store it as XML I suppose, but not as simple to deal with as maybe json.
from formbuilder.
+1 from me too.
JSON format could also fix #109, #111 and #112.
from formbuilder.
+1
from formbuilder.
+1
from formbuilder.
+1
from formbuilder.
Nice solution @AminMkh , but i can't get option values ?
from formbuilder.
@TeqExperts the plugin doesn't seem to support that, you can only save the options keys. It doesn't support a few other things like text fields default value, Just place holders for now.
from formbuilder.
@TeqExperts actually I just checked the XML, it is there, it seems lost when im parsing it. I'll update my code, thanks a lot !
from formbuilder.
That's great. ;) just share the code for me after updating, thank you !
from formbuilder.
@AminMkh I tried to get values but i can't, how did you do it?
from formbuilder.
@TeqExperts I couldn't parse it either, whenever I use
simplexml_load_string($form_data);
The option values are lost, I will try to find another PHP parser. I'll keep you posted.
from formbuilder.
Sorry, don't know if it's ok to past link for ext project. But I've spent the whole day to find pretty formbuilder which works out of the box and provides json data (I'm using postgres json). http://dobtco.github.io/formbuilder/ , could not find repo with project so copied all files from this sample.
from formbuilder.
@AminMkh do let us know if you updated the parser...i'm kinda lost looking for this solution
thanks in advance
from formbuilder.
There are a number of ways to accomplish data prep for your backend, which one depends on your specific app or website. I'm closing this issue as the discussion has strayed too far from topic and the topic is outside of formBuilder's scope.
from formbuilder.
Related Issues (20)
- formBuilder not restoring typeUserAttr select value on setData HOT 26
- TinyMCE fields don't load userData HOT 2
- when we have two forms in the same page, the toggle checkbox doesn't work in the second form HOT 7
- Downloading ZIP or TAR Windows reports Virus HOT 6
- Error label value set data HOT 7
- Grouping controls HOT 9
- How To selected setData element select multiple HOT 2
- Restrict elements in form builder. HOT 1
- How to get HTML code in formBuilder using react HOT 1
- Multiple Form Render Issue HOT 1
- Inline Controls HOT 1
- ASP core mvc / blazor HOT 1
- Group Control - Super Urgent, please advise. HOT 4
- Group Control - Super Urgent, please advise. #1552 HOT 1
- How we can show the uploaded file(s) in file input ( using formbuilder ) ? HOT 1
- Text Area Component allows input of negative value in the Rows field HOT 1
- When Select component only has x2 options a non-functioning Remove Element button is still present HOT 1
- Can I provide custom order(alphabetical) to the fields? HOT 6
- How to custom label header ? HOT 2
- Adding field type button - Label not set HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from formbuilder.