Hi all,

I am using drupal 6.
We have a custom module based on Webform with additional credit card processing features and a few other additions.

Using this module i need to create a single Webform (node) that has some additional PHP/JavaScript which does not exist in the module itself (my additional PHP/Javascript is connecting to Oracle through web services and populating logged in user fields into the form).
I need this custom functionality for just one Webform (node).

1.) I was able to do what i need adding the additional PHP/JavaScript from within Drupal Admin, going into that particular Webform interface, choosing 'input format' to PHP and adding the code into that textarea. Will you recommend this approach?
I know that this way code goes into DB.
2.) Another approach i tried was adding php into my module to generate a custom block (loading that particular webform into the block through nid). Then i created a panel and added the block to it. The problem with this approach was this: on form submition URL changes from Panel's URL to the Webform's URL which is not user friendly, i want to have a single page for Error Messages, Confirmation, etc...

Any direction/suggestions on the above is appreciated.

Regards,
Hayk

Comments

John_B’s picture

Enabling PHP module is pretty horrible, as quite apart from security issues, once you start using it you can run into maintenance problems in the longer term when you have random bits of php or js mixed in with your content in the database.

It is not clear from your question whether you want to use Panels, or whether that was just a by-product of the method you are using. If you do not need panels it is easier, you can just add javascript / jQuery to a single node. It is easy to do by making a theme template for that node only (see here https://www.drupal.org/node/1089656 as well as tutorials on theme suggestions). Or you can have a small module. For adding the js look at tutorials on drupal_add_js() (or the excellent chapter on jQuery in Apress, Definitive Guide to Drupal 7 book).

There is a site-builder (i.e. no coding) alternative, the 'code per node' module (https://www.drupal.org/project/cpn), which still puts code in the db but is somehow cleaner than just enabling php module.

For loading js without loading a the page document, primarily for Ajax, research 'Drupal behaviours.' I think that is D7 and you are on D6 so maybe not useful.

Digit Professionals specialising in Drupal, WordPress & CiviCRM support for publishers in non-profit and related sectors

hzakaryan’s picture

Thanks John,

I tried adding a custom tmpl file for my node, but could not make it work.

Here is my theme template structure:
/themes/mytheme
/node
node-webform.tpl.php
node.tpl.php

i tried adding node-mynodeid-webform.tpl.php and also node-mynodeid.tpl.php under /themes/mytheme/node folder but neither worked.
Can the reason be celan URL-s?

Thanks,
Hayk

John_B’s picture

No idea why it is not working. Is it not working in the sense that it is totally not recognized? Or is it recognized but not loading your js?

In Drupal 5 you probably want something like page-node-1.tpl.php (with 1 replaced by node number), then you can load the js in your footer. Or if you want to load it in the header this is normally done by putting a copy of the core html.tpl.php in your theme then hacking it. You can load the js there with an if statement to locate the correct node.

Digit Professionals specialising in Drupal, WordPress & CiviCRM support for publishers in non-profit and related sectors

hzakaryan’s picture

Thanks for your reply John.

Worked just fine, I had a typo.