call {FormBuilder} inside a javascript code

General project discussion. NOT for help questions.
Post Reply
Mich-adg
Forum Members
Forum Members
Posts: 199
Joined: Sat Aug 02, 2008 9:08 pm

call {FormBuilder} inside a javascript code

Post 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.
spcherub
Power Poster
Power Poster
Posts: 402
Joined: Fri Jun 06, 2008 5:54 pm

Re: call {FormBuilder} inside a javascript code

Post 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
Mich-adg
Forum Members
Forum Members
Posts: 199
Joined: Sat Aug 02, 2008 9:08 pm

Re: call {FormBuilder} inside a javascript code

Post by Mich-adg »

oohh... ok thanks for the help, i'll try another solution...
Post Reply

Return to “General Discussion”