Simple form submit

Questions and answers for designing and implementing forms in Servoy

Simple form submit

Postby tim » Tue Sep 24, 2019 11:14 am

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
tim
 
Posts: 1
Joined: Mon Sep 23, 2019 8:53 am

Re: Simple form submit

Postby mboegem » Tue Sep 24, 2019 12:32 pm

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!
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image

Partner of Tower - The most powerful Git client for Mac and Windows
User avatar
mboegem
 
Posts: 1742
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: Simple form submit

Postby paronne » Tue Sep 24, 2019 12:49 pm

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
paronne
 
Posts: 202
Joined: Fri Nov 02, 2012 3:21 pm


Return to Forms

Who is online

Users browsing this forum: No registered users and 7 guests