Page 1 of 1

Adding form results to a database table?

Posted: Fri Jul 17, 2009 10:35 pm
by jayp70
Is it possible to use Form Builder to create a form then save the results to a database table of your choice?

I've created a database table with 4 fields, then used Formbuilder so when I submit the form the results get saved in this table?

Re: Adding form results to a database table?

Posted: Fri Jul 17, 2009 10:59 pm
by Coldman
Read Help for FormBuilder

Code: Select all

*Store Results in Database. This will store the form contents in an internal database. You will always use this disposition if you use the form with FormBrowser.

Re: Adding form results to a database table?

Posted: Fri Jul 17, 2009 11:14 pm
by Dee
Coldman wrote: Read Help for FormBuilder

Code: Select all

*Store Results in Database. This will store the form contents in an internal database. You will always use this disposition if you use the form with FormBrowser.
That was my first reaction too but I deleted it :) The thing is that stores the result in the database for use by the FormBrowser module, not in a table by choice.

The solution would be something like adding a field with type:
*Call A User Defined Tag With the Form Results
and creating an UDT looking something like this:

Code: Select all

global $gCms;
$db =& $gCms->GetDb();

$query = "INSERT INTO test (name, birthdate, email) VALUES ({$param['name']}, {$param['birthdate']}, {$param['email']})";

$db->Execute($query);
However I'm not getting this to work at the moment, in the called UDT there is no parameter $param available as is said in the module help:
*Call a User Defined Tag With the Form Results. This submits all the form results to the User-Defined Tag you specify. The UDT can handle the results however it wants. Values are passed as $param['field_name'].
Kind regards,
D

Re: Adding form results to a database table?

Posted: Fri Jul 17, 2009 11:23 pm
by Coldman
Dee wrote:

Code: Select all

global $gCms;
$db =& $gCms->GetDb();

$query = "INSERT INTO test (name, birthdate, email) VALUES ({$param['name']}, {$param['birthdate']}, {$param['email']})";

$db->Execute($query);

I think it should be $params

/Coldman

Re: Adding form results to a database table?

Posted: Fri Jul 17, 2009 11:32 pm
by Dee
Coldman wrote: I think it should be $params

/Coldman
Correct it's a typo in the help, they are assigned as $params['Field Name']

Regards,
D

Re: Adding form results to a database table?

Posted: Fri Jul 17, 2009 11:42 pm
by Coldman
btw Dee you have right about this.
UDT is the answer to his question and I'm man enough to admit my error ;).

/Coldman