Page 1 of 1

call {FormBuilder} inside a javascript code

Posted: Wed Jun 01, 2011 6:16 pm
by Mich-adg
Hi,

i try to call a form from the FormBuilder mod. inside a javascript code like this just after the body tag :

Code: Select all

{literal}
<__script__ type="text/javascript">

   if((navigator.userAgent.match(/iPhone/i))||(navigator.userAgent.match(/iPod/i))||(navigator.userAgent.match(/iPad/i))) {

   alert ("ipad/iphone");

   } else {

   document.write('<div id="form_contact" class="standard"><img src="images/design/btn_contact.png" id="btn_contact" />{/literal}{FormBuilder form='contact'}{literal}</div>');

   }

</__script>
{/literal}
The write function doesn't go to the ending "div" apparently because a </__script> is generated by the form, but i don't know where this javascript tag is written (i looked in the template of my form but nothing...).

Any idea? Thx.

Re: call {FormBuilder} inside a javascript code

Posted: Wed Jun 01, 2011 7:02 pm
by spcherub
This should not work in principle. Here's why:

Javascript is interpreted on the client side - this means that the page is loaded and rendered on the client, the JS fires off, then does not know what to do with what is essentially a server-side Smarty tag.

You will have to handle your conditional logic differently. You could copy and paste the output of FormBuilder into your JS, but that is not the best option for maintenance (you will have to repeat the paste operation every time you update the form).

Hope that helps.

S

Re: call {FormBuilder} inside a javascript code

Posted: Wed Jun 01, 2011 7:11 pm
by Mich-adg
oohh... ok thanks for the help, i'll try another solution...