CMS Made Simple Forums
https://forum.cmsmadesimple.org/

CGBetterForms and LISE
https://forum.cmsmadesimple.org/viewtopic.php?f=7&t=80687
Page 1 of 1

Author:  WDJames [ Thu Apr 25, 2019 11:17 am ]
Post subject:  CGBetterForms and LISE

Hi all,

I've recently started using CGBetterForms as a replacement for FormBuilder.

With FormBuilder I was able to take the form data and insert it to LISE via a UDT.

I've tried to follow the help page from CGBetterForms and used the "Stop processing dispositions based on a condition" disposition and within that template called my UDT.

I can confirm that the UDT is being triggered but I need a way of getting the form submission values into the UDT. For my test, I'm using the Sample contact form with the following fields: name, email, comments.

Below is my UDT:

\$1:
$mod = cmsms()->GetModuleInstance('LISEContactFormDatabase');
if(!is_object($mod))
return;

$obj = $mod->InitiateItem();

$obj->title = $name;

$mod->SaveItem($obj);


The code above submits the form but the "$name" variable is blank and no LISE item is created.

Any ideas would be greatly appreciated.

Thanks,

James

Author:  velden [ Thu Apr 25, 2019 1:26 pm ]
Post subject:  Re: CGBetterForms and LISE

A working example (shortened):

Note I use some GUID (cgbf_requestid) generated by CGBF as an alias. Works for my case, but may be you need something different.

\$1:
{UDTNameHere formdata=$response}


\$1:
$d = $params['formdata'];

$mod = \cms_utils::get_module('LISEExample');

$item = $mod->LoadItemByIdentifier('alias', $d->get_field_value('cgbf_requestid'));

$item->email = $d->get_field_value('kfrm_p_inp_email');
$item->thema = $d->get_field_value('kfrm_inp_theme');
$item->datum = strftime('%Y-%m-%d',$d->get_field_value('kfrm_inp_date'));

$mod->SaveItem($item);

Author:  WDJames [ Thu Apr 25, 2019 2:18 pm ]
Post subject:  Re: CGBetterForms and LISE

Hi Velden,

Thanks for the reply and for providing an example. I was able to make it work with my code by taking some things from your example. Below is what I ended up with:

UDT:

\$1:
{savecontactformdata formdata=$response}


Code:

\$1:
$d= $params['formdata'];

$mod = cmsms()->GetModuleInstance('LISEContactFormDatabase');
if(!is_object($mod))
return;

$obj = $mod->InitiateItem();

$obj->title = $d->get_field_value('name');
$obj->email = $d->get_field_value('email');
$obj->comments = $d->get_field_value('comments');

     
$mod->SaveItem($obj);


If I'm being cheeky, I'd like to expand on this code by adding a foreach loop that cycles through the LISE fields and insert data from the equivalent inputs so that each field doesn't need to written separately.

Thanks for your help.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/