I am working on my first (simple) form in Servoy, this form contains 3 input fields; name, email and content. I have connected the dataProviders from my input fields to my database table (postgressql), the only thing that’s left is the submit button that inserts the user input into my database.
I was wondering if someone could help me out so that when i click the submit button, the data gets inserted to my database table.
By default Servoy has ‘autoSave’ enabled.
Normally this will result in a direct save of your data into the database.
In case you want to handle this manually, you can set the autoSave state to be disabled when you enter the form
databaseManager.setAutoSave(false)
You have to attach on onAction method (function) to the onAction event handler of your submit button.
All this function should do is a simple save of the data
databaseManager.saveData()
Optionally you could pass this the current record in order to make Servoy only write this particular record to your database
welcome !
your database is probably empty; dataprovider are bound to the selected record of your foundset, which will be ‘none’ if no data is available;
therefore before you can insert any data you can create a new record with the call.
foundset.newRecord();
this instruction will create a new record into your form’s foundset.
As Marc has mentioned, if auto-save is turned on (which is the default) the record will be immediately insert into the database.
With auto-save switched off you can control it using the databaseManager.saveData as Marc suggested and perform the save when the user clicks the Submit button.