Page 1 of 1

Simple form submit

PostPosted: Tue Sep 24, 2019 11:14 am
by tim
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.

This is my form
Image

My postgressql database
Image

What shows up when i click 'dataProvider' on my submit button
Image

Thanks in advance

Re: Simple form submit

PostPosted: Tue Sep 24, 2019 12:32 pm
by mboegem
Hi tim,

welcome to the Servoy forum!

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
Code: Select all
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
Code: Select all
databaseManager.saveData()


Optionally you could pass this the current record in order to make Servoy only write this particular record to your database
Code: Select all
databaseManager.saveData(foundset.getSelectedRecord())


Hope this helps!

Re: Simple form submit

PostPosted: Tue Sep 24, 2019 12:49 pm
by paronne
Hi Tim,

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.

Code: Select all
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.

Regards,
Paolo