Page 1 of 1

[Solved] FormBuilder and using a UDT to provide feedback

Posted: Tue Jul 22, 2014 2:39 pm
by inetelle2
Hello (added more info 7/23),

Feeling a little in the dark here so reaching out for help! I have a form set up to receive user input (a zip code). I want to feed that input into a UDT then return the results to the user. I seem to be having trouble getting the input into my UDT.

I have a field setup of type 'Call A User Defined Tag With the Form Results', referencing my UDT. I have my UDT built expecting to access the $params array. How do I get the form to pass the field data to the UDT on submit, then display the results of my UDT?

Currently I have the call to my UDT on the submission template. I have also tried putting it on the same page as the form. Neither gets me the form data passed to the UDT so my UDT ends up displaying 'nothing given to me' but I think this is just because the UDT is being called by the page, not the form.

I seem to be missing a vital piece of understanding in how the form interacts with the UDT and what happens after the submission of the data to the UDT. I have it set for a simple string return so how do I get that string to display?

Thanks

Here is my UDT:
*****************************************************
global $params;

$zipcodes = array(
"85224" => "AZ Chandler",
"85322" => "AZ Arlington",
"85323" => "AZ Tolleson",
"85326" => "AZ Buckeye",
"85335" => "AZ El Mirage",
"85340" => "AZ Litchfield Park"
);
if(!empty($params['zipcode']))
{
if(array_key_exists($params['zipcode'], $zipcodes))
{
return "Yes, we provide coverage in " . $zipcodes[$params['zipcode']] . ". Please fill out the form so we can get in touch with you to setup service.";
}
else
{
return "We do not currently service that area. Please fill out the form to be notified when we expand coverage.";
}
}
else
{
return "Nothing given to me";
}
*****************************************************

Re: FormBuilder and using a UDT to provide feedback

Posted: Sat Jul 26, 2014 9:04 am
by Jos
When you use the UDT in the FormBuilder Submission template, you can call it like this (assuming your field is called "zipcode"):

{yourUDTname zipcode=$zipcode}

note that $zipcode is the variable from FormBuilder. Check the Submission Template tab the in FormBuilder admin to see all the variables you can use.

Now, within the UDT you can use the variable $params['zipcode'].
You do not need global $params; . Delete that.

And in stead of return, you can echo the result sentences.

You can find some more documentation on how to write UDT's here: http://docs.cmsmadesimple.org/tags/user ... ting-a-udt

Re: FormBuilder and using a UDT to provide feedback

Posted: Mon Aug 11, 2014 3:49 pm
by inetelle2
Thank you, Jos. I really appreciate your input!

I ended up creating a variable called UDTresponse, using $smarty->assign to set my string response to that variable then calling the variable on the Form Submission template.

I was not initially getting any data passed to my UDT by using the 'Call a UDT With the Form Results' field type but I think this may have been due to my page & my form having the same name. I started over and made sure every object had a different name by starting a naming convention for forms (fbFormName). Seems to have done the trick.