Page 1 of 2

Save form data to xml

Posted: Tue Jul 30, 2013 2:39 pm
by aman

Hi, I'm new to this game so please don't flame me! I have created a simple questionnaire app using your wonderful service (it really is a dream!) however I'm stuck on the coding aspect. I want to save all the data that has been input on my form as a .csv or .xml file to the app and then have a button to sync when I have internet connectivity to a external hosted server. It is essential that this app must be able to save locally as I will not always have internet connectivity.

Thanks!


Save form data to xml

Posted: Tue Jul 30, 2013 3:53 pm
by maxkatz

Please check our tutorials, there is a tutorial on how to save data into local in-browser database. As for syncing - this is something you would need to developer. What you are trying to build is possible, but does require a pretty strong knowledge of JavaScript.


Save form data to xml

Posted: Wed Jul 31, 2013 9:50 am
by aman

http://docs.appery.io/tutorials/build...

using that particular tutorial i've managed to use the button to save one item, is there any way to get it to read all of the sections and record the values. also does this save as a .csv or .xml?


Save form data to xml

Posted: Wed Jul 31, 2013 11:37 am
by Maryna Brodina

Hello! You can create string which contains xml or csv and save it into localStorage
codevar xmlStr = '<?xml version="1&#46;0"?><root>';
xmlStr = xmlStr + "<elem1>" + Appery("input1Name")&#46;val() + "<&#47;elem1>&quot
xmlStr = xmlStr + "<elem2>" + Appery("input2Name")&#46;val() + "<&#47;elem2>&quot
xmlStr = xmlStr + "<&#47;root>&quot
localStorage&#46;setItem("xml", xmlStr);/code
You can create xml with any complex structure.


Save form data to xml

Posted: Wed Jul 31, 2013 12:33 pm
by aman

Hi Marina! Thanks for that. so do I add that to the existing code? Also I've found the code that the button uses to save the data however how do i make it so that it can save all the data instead of just one particular element.

$('#startScreen_mobilecontainer1 [name="mobilebutton_528"]').die().live({
click: function() {
if (!$(this).attr('disabled')) {
setVar_('data', 'startScreen_mobilecheckbox_32', 'checkboxSelected', '', this);
}
},
});


Save form data to xml

Posted: Wed Jul 31, 2013 12:58 pm
by Maryna Brodina

On button Click event add Run JS action and insert code we suggested. Replace input1Name, input2Name with your Input's names. You can add this line codexmlStr = xmlStr + "<elem1>" + Appery("input1Name")&#46;val() + "<&#47;elem1>&quot/code as many times as you need. If you have 10 Inputs - add 10 lines.


Save form data to xml

Posted: Wed Jul 31, 2013 1:03 pm
by aman

So for example i've got two inputs, one called "mobilecheckbox_508" and "mobilecheckbox_509" would it be like this?

$('#startScreen_mobilecontainer1 [name="mobilebutton_528"]').die().live({
click: function() {
var xmlStr = '';
xmlStr = xmlStr + "" + Appery("mobilecheckbox_508").val() + "";
xmlStr = xmlStr + "" + Appery("mobilecheckbox_509").val() + "";
xmlStr = xmlStr + "";
localStorage.setItem("xml", xmlStr);
}
},
});


Save form data to xml

Posted: Wed Jul 31, 2013 1:09 pm
by Maryna Brodina

Please see the screenshot
Image


Save form data to xml

Posted: Wed Jul 31, 2013 1:16 pm
by aman

ah right i think i get it. but how does the javascript know if a box has been ticked or not? or does it? I don't mind building it so it checks every box, could i not do a if statement to check if value is true then store data?


Save form data to xml

Posted: Wed Jul 31, 2013 2:15 pm
by Maryna Brodina

You can select all checked checkboxes http://api.jquery.com/checked-selector/ and use only them, or you can check each checkbox (if it's checked or not) and add them in your xml. It should be part of your app logic.