Form Builder - conditional fields

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
jk
Forum Members
Forum Members
Posts: 30
Joined: Thu Dec 04, 2008 4:47 pm

Form Builder - conditional fields

Post by jk »

Hi All,

I have used form builder a lot for simple contact forms.  I am developing a complicated form at the moment and would like to use form builder again however I am not sure that it is able to handle conditional fields.  I have read the documentation and the forums but I have no answer. Does anyone know the answer to the question below?

I only have one conditional question.  I want to ask people if they are new or existing customers as question 1 - if they are new I want question 2 to show a certain range of values.  If they are exsisting customers I want question 2 to show a different range of values.  All the remaining three pages of the form are exactly the same for both new and existing customers.

Regards, Jenny
jk
Forum Members
Forum Members
Posts: 30
Joined: Thu Dec 04, 2008 4:47 pm

Re: Form Builder - conditional fields

Post by jk »

BUMP

Is there really no way of doing this?
vilkis

Re: Form Builder - conditional fields

Post by vilkis »

Hi,
you can create three questions and show the second or the third question depending on answer to the first question.  For hiding/showing fields use javascript. You can found it by googling or can adapt to your needs the following:

Code: Select all

// <![CDATA[
function display(obj,id1) {
txt = obj.options[obj.selectedIndex].text;
document.getElementById(id1).style.display = 'none';
if ( txt=='existing customers') {
document.getElementById(id1).style.display = 'block';
document.getElementById(id1).value = 'block';
}

}
// ]]>

Vilkis
jk
Forum Members
Forum Members
Posts: 30
Joined: Thu Dec 04, 2008 4:47 pm

Re: Form Builder - conditional fields

Post by jk »

Thanks for the post. 

I have had a go but I know nothing at all about JS and I have not been able to get it to work.  I have posted a commercial job in the relevant forum.

JK
JeremyBASS

Re: Form Builder - conditional fields

Post by JeremyBASS »

Try to split the form in to two pages, you should be able to then do an if statement where you test the value of your first question to form the second...

Hope that helps

Cheers
Jeremy
vilkis

Re: Form Builder - conditional fields

Post by vilkis »

Hi,

@JeremyBASS
Can you explain more detailed, how to do conditional questions with FormBuilder by splitting  a form in to several pages? Are you talking about adding pagebreak in the form?

vilkis
JeremyBASS

Re: Form Builder - conditional fields

Post by JeremyBASS »

It’s really simple just put your first question in the form then add  -Page Break then your next question... so lets say for a second that you have a text field on a page like this one here made just for you...


http://www.digitalbarn.tv/testing-page.html

Which the text area was targeted and having the name of fbrp__7.  Now for me as this was a quick test for you I just looked at the form rendered out... the text area was m5fbrp__7... so I had to add was

{$smarty.post.m5fbrp__7}

to the form... so you'll see that what ever you type in that text area box is now shown on the next page... make it a if statement and you can now hide show ... logic your way into anything...

Hope that helps...

jeremyBass
vilkis

Re: Form Builder - conditional fields

Post by vilkis »

Thank you, JeremyBASS. I have to read Smarty manual more closely  :)

So, I  have to modify template of Form. If I remove a required question from  a form using if statement the form validation is not successful. The only way I found is to add a hidden input instead of the required field that I want to hide. Let say I want to eliminate the required field with name m6fbrp__5. I modify a part of Form template in such a way:
modify

Code: Select all

{foreach from=$fields item=entry}

CODE TO OUTPUT A FIELD

{/foreach}
to this

Code: Select all

{foreach from=$fields item=entry}
{if  $entry->input_id != m6fbrp__5}

CODE TO OUTPUT A FIELD
	
{else} 
<input type="hidden" name="m6fbrp__5" value="SOME PROPER VALUE " />

{/if}
{/foreach}

JeremyBASS, respond, please, if I do it in too complex way.

Regards,
vilkis
JeremyBASS

Re: Form Builder - conditional fields

Post by JeremyBASS »

A faster/simpler way may-be this be to do this...

style="{if isset($smarty.post.m5fbrp__5) && ($smarty.post.m5fbrp__5=="what ever condition")}display:none;{/if}"

I think I'd opt for that but really you could do it many ways as your way should work too... it comes down to the complexity of the form and what will serve it best...

Hope this helps...

Cheers
jeremyBass
Post Reply

Return to “Modules/Add-Ons”