Joomla Webform alternative: JForms

I don’t use Joomla, but sometimes a friend or a colleague of mine ask me some tips. My answer could be: in Drupal it will take 5 minutes.

Since I’m very open-minded, today instead of replying in that awkward way I try to found an alternative to a very useful module for Drupal called Webform. I’ve found a limited but working equivalent for Joomla called JForms.

Tested on:

Installation:

  1. Install the extension using URL installation and paste the extension link (zip file from link above).
  2. Create a new form (see the visual howto below) with at least one field, one button, a form title, and a Thank you page (eg. index.php)
  3. Save the form.
  4. Create a new menu item from Menu > Main Menu > JForms > Standard forms  and fill the Select Form field.

Now that you’ve a form, you can use it from your site (click on menu item written created on (4) ).

If you have to link two forms together (eg. Customers -> Company), you have to use the DBList field.

  1. Create the Firm form
  2. Create the Customers form
  3. On Customers form add a DBList field

DB List field must have these values:

Table name #__jforms_9c7aa
Field key id
Field value hcf94
Field sort hcf94
  • Table name is the table name (mydbprefix_jforms_9c7aa) with the placeholder #__ instead of mydbprefix_.
  • Field key is id. The form select value will be set to an univocal id instead of the raw value.
  • Field value: value as displayed by the user.
  • Field sort: sort the list by this field.

HTML result:

<select style="width: 70px;" id="h4443_14" name="h4443[]">
<option selected="selected" value="1">Barilla</option>
<option value="2">Parmalat</option>
</select>

When creating a new customer, you’ll see a dropdown with a list of companies from the Company table and the two forms are connected.

See also:

How to automatically translate your Drupal module

You’ve created your module. But how to translate it into different languages?

Tested with:

  • Translation template extractor 6.x-3.0
  • Drupal 6.x
  • English default + Italian translation

Prerequisites:

  • Another language active apart default (English)
  • Use t() function for all translatable string, including ones on my_funny_module.admin.inc (Administration interface).

If you use t() function correctly on your module, you can create your own translation using the handy Translation template extractor module.

  1. Download and install Translation template extractor module.
  2. Create a directory named “translations” within my_funny_module directory (your module directory)
  3. Go to admin/build/translate/extract
  4. Select your module from Directory lists
  5. Select “Language independent template” and click “Extract”
  6. Save file to my_funny_module/translations directory as my_funny_module.pot
  7. In the same screen, select “Template file for Italiano translations” (where Italiano is your destination language)
  8. If you’ve already translated some strings into Italiano language, check “Include translations” to include these strings
  9. Click “Extract”, and save file to my_funny_module/translations directory as it.po, where “it” is the ISO 639-2 code for Italiano language
  10. You can add information about translation changing the first part of both files (translator mail, name, etc.)

Now, when you install your module translation strings will be added automatically. If you apply some changes to these files, and in any case the first time you complete this procedure on an active module, you have to refresh translation cache. To do this, go to admin/build/translate/refresh and use Refresh strings and Update translations after you’ve checked all boxes. If problem persists (strings are not updated or you got some weird errors), try to reinstall your module.

Disable upload and comment for a new content type programmatically

Following code is useful when installing a module that create a new content type programmatically on Drupal 6.x.

Basically, it adds two variables setting default values for comments (core Comment module) and attachments (core Upload module).

Code to write on my_funny_module/my_funny_module.install.

function my_funny_module_install() {
  // Disable attachments
  // Read http://api.drupal.org/api/function/upload_nodeapi/6 on "load"
  variable_set("upload_my_content_type", 0);

  // Disable comments for this content type
  // Read http://api.drupal.org/api/function/comment_form_alter/6
  variable_set('comment_my_content_type', COMMENT_NODE_DISABLED);

  // Install schema as usual (if any)
  drupal_install_schema('my_funny_module');
}

Note that this code assign only default values for my_content_type: as any content type, this value could be later changed via GUI.

Node import and domain access

If you are using Node import 1.x-rc4 or below with Domain Access, you can get this error on each row to be imported:

An illegal choice has been detected. Please contact the site administrator.

This error in this case is presented when Domain Access try to import a node without assigning it to a domain. Node import 1.x-rc4 and below  lacks Domain Access support on 1.x-rc4.

Domain Access support will be available on Node import by 1.0 RC5 version, you have to dowload the -dev version to have it now.

After that, the error should disappear. For more information, read the first lines of node_import/node_import.inc , where this error is explained.

Print module customization

Tested on: Drupal 5.7, Print 3.4

Drupal Printer Friendly module (Print) add “print this” functionality to nodes. Customization is pretty easy: according to README file you can add a print.tpl.php to your theme (or subtheme) directory and modify it. All override templates are (in check order):

  1. print.__node-type__.tpl.php in the theme directory
  2. print.__node-type__.tpl.php in the module directory
  3. print.tpl.php in the theme directory
  4. print.tpl.php in the module directory (supplied by the module)

You can copy the default print.tpl.php in module directory (4) to one of the 1-3 destinations files, then customize it. You can also use variables like $node->changed to enrich your template. You can read the dynamically generated list by Content Template module, if you have installed it.