aman
Posts: 0
Joined: Tue Jul 30, 2013 2:39 pm

Save form data to xml

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!

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Save form data to xml

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.

aman
Posts: 0
Joined: Tue Jul 30, 2013 2:39 pm

Save form data to xml

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?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Save form data to xml

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.

aman
Posts: 0
Joined: Tue Jul 30, 2013 2:39 pm

Save form data to xml

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);
}
},
});

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Save form data to xml

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.

aman
Posts: 0
Joined: Tue Jul 30, 2013 2:39 pm

Save form data to xml

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);
}
},
});

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Save form data to xml

Please see the screenshot
Image

aman
Posts: 0
Joined: Tue Jul 30, 2013 2:39 pm

Save form data to xml

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?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Save form data to xml

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.

Return to “Issues”