FORUMS


The Form Tools forums are no longer active, but the old posts have been archived here. Please see the Help page on how to get help / report issues.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FormBuilder - new JS resource loading as style!
#1
Hi,
Thank you for your great work,

I added a resource to one of my default template sets as JS and placed the placeholder code in the templates, in "header" one. the code is loading but as a Style not JavaScript!
The "Resource Type" is "JS"!

What is wrong with me?
Reply
#2
Same issue.

At the very least, does anyone know if this feature simply doesn't work, or are we doing something wrong? Please reply if adding a JS resource works for you at all.

Thank you.
Reply
#3
It appears form builder's function fb_generate_form($settings) does not check the resource type yet, and serves all resources as css.

See \modules\form_builder\global\code\generator.php , beginning line 256.

This bug also appears in the bug tracker:
Issue #365 ยป JavaScript Form Builder Resource applied as CSS Sheet, when specified as JavaScript type

For the time being, the best option is likely to upload a js file elsewhere, and hard code the script link into your template. That won't achieve what css.php does, as far as access control (It looks like it won't serve resources for a private form unless you're logged in, which is nice to know, if I find a reason for private forms).

Alternately, you can live dangerously, and do this for the current version:
Core 2.2.6
Formbuilder 1.0.7

Copy File:
\modules\form_builder\global\form_resources\css.php
to
\modules\form_builder\global\form_resources\js.php

In the new copy, js.php,
Change line 10:
PHP Code:
header("Content-Type: text/css"); 
to:
PHP Code:
header("Content-Type: text/javascript"); 

Make a backup copy of file:
\modules\form_builder\global\code\generator.php
Replace line 260:
PHP Code:
$link "<link type=\"text/css\" rel=\"stylesheet\" href=\"$g_root_url/modules/form_builder/global/form_resources/css.php?resource_id=$resource_id&nocache=$now{$query_str}\">"
with:
PHP Code:
    $resource_type $resource_info["resource_type"];
    if(
$resource_type == 'js') {
      
$link "<script type=\"text/javascript\" src=\"$g_root_url/modules/form_builder/global/form_resources/js.php?resource_id=$resource_id&nocache=$now{$query_str}\"></script>";
    } else {
      
$link "<link type=\"text/css\" rel=\"stylesheet\" href=\"$g_root_url/modules/form_builder/global/form_resources/css.php?resource_id=$resource_id&nocache=$now{$query_str}\">";
    } 

No warranty provided that this is fit for any purpose. It will likely break if form builder is updated, and the bug is not fixed in the update. These instructions may not work for, or may break future or past versions.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)