Page 1 of 2

HowTo set in FormBuilder input-hidden=UDT-value ?

Posted: Mon Mar 24, 2014 10:36 pm
by coni99
Hello,

please how can I assign UDT-value to input-hidden field in FormBuilder before form submission by the user ?

Thanks

Re: HowTo set in FormBuilder input-hidden=UDT-value ?

Posted: Tue Mar 25, 2014 8:00 am
by uniqu3
you can insert a value for a field by using value_fld* parameter (see FormBuilder help), so for example you could call your form {FormBuilder form='my_form' value_fldIDOFTHEFIELD=$your_udt_output_variable}

Re: HowTo set in FormBuilder input-hidden=UDT-value ?

Posted: Tue Mar 25, 2014 3:47 pm
by coni99
Thanks, it works although I had different declaration :

{FormBuilder form='sp_Fusion' value_sp_username={logged_user_name}}

Re: HowTo set in FormBuilder input-hidden=UDT-value ?

Posted: Tue Mar 25, 2014 6:06 pm
by coni99
Unfortunately there is still a problem to save this data as a string in db..

I have this declaration :
{FormBuilder form='sp_Fusion' value_sp_username={logged_user_name}}

which produces this html :
<input id="fbrp__52" type="hidden" value="coni_FEU2" name="mc41d9fbrp__52">

and problem appears after submitting the form :
Warning: strlen() expects parameter 1 to be string, array given in /customers/9/e/e/lbi-archpro.org/httpd.www/als-filtering/modules/FormBuilder/classes/DispositionFormBrowser.class.php on line 284 Warning: htmlspecialchars() expects parameter 1 to be string, array given in /customers/9/e/e/lbi-archpro.org/httpd.www/als-filtering/modules/FormBuilder/classes/Form.class.php on line 2519

I don't understand why is apparently string value converted to array ??

Re: HowTo set in FormBuilder input-hidden=UDT-value ?

Posted: Thu Mar 27, 2014 9:58 am
by psy
Try assigning the username to a var before the formbuilder tag or if you are using CustomContent:

Code: Select all

{FormBuilder form='sp_Fusion' value_sp_username=ccUser::username()}
I have also found in the past that FB is a bit quirky about field id vs field name. I always use the field id to be sure when setting default values in the FB tag.

Re: HowTo set in FormBuilder input-hidden=UDT-value ?

Posted: Thu Mar 27, 2014 10:11 am
by velden
And don't know if it's related but make sure you do NOT use Fb 0.7.4

http://forum.cmsmadesimple.org/viewtopi ... 64#p308864

As you say the output is

Code: Select all

<input id="fbrp__52" type="hidden" value="coni_FEU2" name="mc41d9fbrp__52">
I don't think that you need to assign to a variable first.

Re: HowTo set in FormBuilder input-hidden=UDT-value ?

Posted: Wed Apr 02, 2014 10:31 pm
by coni99
Guys thanks for support, however it seems this problem is bigger than it looks. I've installed FB 0.7.3, no change.. I've set new definition :

Code: Select all

{FormBuilder form='sp_Fusion' value_fld30={logged_user_name}}
but no change still.. I've also tried to call the method directly instead of calling it from UDT but this ended up in error.. So I don't understand how Smarty handles php custom code and how can I use this code :

Code: Select all

$feu_module = cms_utils::get_module('FrontEndUsers');
$result = $feu_module->LoggedInName();
echo $result;
instead of putting it into UDT and use it directly in page editation ? I could thus avoid using UDT which seems to be a problem for the system to parse as string..

Re: HowTo set in FormBuilder input-hidden=UDT-value ?

Posted: Wed Apr 09, 2014 8:32 am
by faglork
I can confirm that: strings get converted to arays. Apparently, the code segment which takes care of the "parameter override" gets executed TWICE, since the generated ARRAY contains the original STRING as items [0] and [1]. BTW, the "variable-to-array-conversion" bug has alredy been reported in the bugtracker. Unresolved so far.

I found a workaround: In the e-mail template, just don't call the field parameter, but the first item of the array, like so:
{if $fld_41 != ""} Value: {$fld_41[0]}{/if}

But I still have a similar problem - I don't use an UDT to hand over the parameter, but a POST parameter which I insert into the module call:

{FormBuilder form='myform' value_fld30=$smarty.post.param1}

which builds a nice form and all ... but the form simply does not get processed on submit. If I put in a static value:


{FormBuilder form='myform' value_fld30='MyValue'}

then I get an identical form which gets processed (apart from the "array bug"). Form HTML code, HTTP headers sent and POST parameters in both cases are IDENTICAL, whether I use $marty.post.param1 or a static value.

I am at my wits end here ... I just don't know where to look. What can prevent a form form getting processed?

Right now, the parameter override in FB is quite useless. Hope we can find a solution, since this prevents a LOT of very nice & simple cross-connections between modules and formbuilder. If it just worked as described in the module help ...

One question: Does someone have a working installation of formbuilder where the parameter override works?

Cheers,
Alex

Re: HowTo set in FormBuilder input-hidden=UDT-value ?

Posted: Wed Apr 09, 2014 8:40 am
by faglork
velden wrote:And don't know if it's related but make sure you do NOT use Fb 0.7.4

http://forum.cmsmadesimple.org/viewtopi ... 64#p308864

As you say the output is

Code: Select all

<input id="fbrp__52" type="hidden" value="coni_FEU2" name="mc41d9fbrp__52">
I don't think that you need to assign to a variable first.
a) the bug is the same in 0.7.4 and 0.7.3 ...

b) if you want to hand over a parameter to the formbuilder module, you *have* to use a variable otherwise you'd have to hardcode each and every possible form.

Cheers,
Alex

Re: HowTo set in FormBuilder input-hidden=UDT-value ?

Posted: Wed Apr 09, 2014 12:18 pm
by uniqu3
Have you tried using strval on variable, to truly get string returned, even i haven't faced any issues with FB 0.7.3 or earlier when used with value_* parameter, but i do always use ID so value_fldIDNUMBER.

Basically you can try:

Code: Select all

{$set_value = strval($smarty.post.param1)}
{FormBuilder form='myform' value_fld30=$set_value}
or

Code: Select all

{FormBuilder form='myform' value_fld30=$smarty.post.param1|strval}
or you can simply do some logic in your FormBuilder template, inside foreach loop where you check against ID of the field which is supposed to have that variable as value and build input field yourself.

Code: Select all

{if $entry->input_id == 'something'}
    <!-- example as hidden field -->
    {$set_value = $smarty.post.param1} {* <-- if this param is sent via url to form, shouldn't this be "get" ?? *}
    <input type="hidden" name="{$actionid}{$field->input_id}" value="{$set_value|default:''}" />
    {/if}
{else}
    {$entry->input}
{/if}
{* and so on *}
All of this is untested, but hope you figure your way out.

Re: HowTo set in FormBuilder input-hidden=UDT-value ?

Posted: Wed Apr 09, 2014 12:44 pm
by psy
Seems to me that the problem is too hard. It should be easy to insert the $param or $params['some-assoc-array-val'] or $_REQUEST['whatever'].

What do you get when in your UDT, you simply print_r($params); die;

Re: HowTo set in FormBuilder input-hidden=UDT-value ?

Posted: Wed Apr 09, 2014 12:50 pm
by psy
As a comparison, in your UDT, try print_r($_REQUEST), die; and ensure that the outputs are the same.

Re: HowTo set in FormBuilder input-hidden=UDT-value ?

Posted: Wed Apr 09, 2014 5:28 pm
by faglork
uniqu3 wrote:Have you tried using strval on variable, to truly get string returned, even i haven't faced any issues with FB 0.7.3 or earlier when used with value_* parameter, but i do always use ID so value_fldIDNUMBER.

Basically you can try:

Code: Select all

{$set_value = strval($smarty.post.param1)}
{FormBuilder form='myform' value_fld30=$set_value}
this changes nothing
uniqu3 wrote: or

Code: Select all

{FormBuilder form='myform' value_fld30=$smarty.post.param1|strval}
this makes the form disappear completely.

I still have to test the other canges you suggested.

Thanks,
Alex

Re: HowTo set in FormBuilder input-hidden=UDT-value ?

Posted: Wed Apr 09, 2014 5:30 pm
by faglork
psy wrote:Seems to me that the problem is too hard. It should be easy to insert the $param or $params['some-assoc-array-val'] or $_REQUEST['whatever'].
Yes, especially if you consider that this is the method endorsed in the module help ...

Cheers,
Alex

Re: HowTo set in FormBuilder input-hidden=UDT-value ?

Posted: Wed Apr 09, 2014 6:06 pm
by faglork
Strange ...

when I name the variable the same as the FB field, it works.

Example:

This is how the page containing the form is called:

Code: Select all

<form action="{cms_selflink href='form' }" method="post" name="formular">
    <input type="hidden" name="mba7f1fbrp__41" value="Fachpraxis Nr. 1" />
    <input type="submit" value="zum Formular" />
</form>
The FB module call:
{FormBuilder form="anfrage" value_fld41=$smarty.post.mba7f1fbrp__41}

This works! Still has the "ARRAY-Bug", but at least it works.

UNFORTUNATELY, this works only with ONE example. If you have several calls for the form with different parameters, it fails because the fjeld name changes from form to form. The ID stays, but it does not work with the ID :-(

This bugs me a lot.
Alex