Changelog from Webform 3.x to 4.x

This page documents changes between the Webform 3.x version and the Webform 4.x version, including any information you need to know when upgrading from one version to the next.

Programmatically modifying a webform with hook_form_alter()

A webform node will respond to a call to hook_form_alter() just like any other form built with the Form API.

However, the structure of the node is different from your average form and can catch you out.

hook_form_alter() will provide you with three things with which to work: the $form variable itself, the form's unique identifier and $form_state, which will include any submitted values. $form is the container for the form components, so that is where to look to make your modifications.

Webform

The Webform module is used for making one-off custom surveys, contests, personalized contact forms, or petitions within your Drupal site. You could even to request studio reservations or something like that before implementing a more complicated solution like the Reservations API.

This documentation was written to explain how to configure and install Wysiwyg as part of a Community Media installation. The existing Webform Documentation by LinL contains extra useful information.

Enabling Webform

  1. Navigate to Administer > Modules
  2. Select Webform in the Webform block
  3. Scroll to the bottom of the page and click Save Configuration

Configuring Webform

Webform is now ready to use, although with a full range of options, which you can adjust by navigating to Administer > Configuration > Content Authoring > Webform Settings

Further configuration of the Webform Content type is done by navigating to Administer > Structure > Content Types > Webform and click on the Edit tab.

Scroll down to the bottom tabs on the left hand side of the page

When to use Entityform

When I was first researching Entityform and other survey form modules, I had four basic questions I was trying to resolve.

  1. I don't want to create a survey form, so why would I want to use a survey form module?
  2. How does Entityform help solve my problem?
  3. When should I use it
  4. How is it different from other solutions?

After doing some research and talking with Tedbow, this modules author, I think I can start to answer these questions.


I don't want to create a survey form, so why would I want to use a survey form module?

I just had this same discussion with a friend of mine the other day. She wanted to include a signup form at the bottom of an event content type node. This sign up form would allow people to register for the event. (Yes, I know she could’ve used the signup module. However she needed more functionality than the signup module offered.) I suggested she use either Entityform or Webform. Her immediate response was "I want to create a signup form, not a survey form". And therein lies the confusion of “survey” form modules.

Custom coding: Adding advanced validation or submit code

An example for your particular use-case would look like the following:

- Make a new directory in sites/all/modules called "mywebform_extra".
- Make a new text file in sites/all/modules/mywebform_extra called mywebform_extra.info. Put this inside of it:

name = Webform Extra
description = Customizations for the Webform module.
core = 6.x
package = Webform
dependencies[] = webform

- Make a new text file in sites/all/modules/mywebform_extra called mywebform_extra.module. Put this inside of it:

<?php
/**
* Implementation of hook_form_alter().
*/
function mywebform_extra_form_alter(&$form, &$form_state, $form_id) {
// Add validation for a particular Webform node:
if ($form_id == 'webform_client_form_44') {
// Simply add the additional validate handler.
$form['#validate'][] = 'mywebform_extra_validate_44';

// Add the submit handler after the existing Webform submit handler,
// but before the second Webform handler. Pop off the first one and add
// ours second.
$first = array_shift($form['#submit']);
array_unshift($form['#submit'], $first, 'mywebform_extra_submit_44');
}
}

/**
* Validation handler for Webform ID #44.
*/
function mywebform_extra_validate_44(&$form, &$form_state) {
global $user;
if (!isset($user->roles[4])) {

Pages

Subscribe with RSS Subscribe to RSS - webform