Chapter 8. Acting on Webform Submissions

In this chapter, we will cover the following topics:

  • Modifying submitted data
  • Adding custom validation

Introduction

Although this chapter only deals with two topics, it covers a lot of ground in doing so. We're going to explore some of the possibilities that exist for interacting with submissions after our form users click on the Submit button. Both the Webform and Webform Validation modules enable developers to act upon the submitted data before the data reaches the database.

In Chapter 6, Extending Webform, we touched on one of the programming hooks exposed by Webform, defining custom option lists. Many core and contributed modules expose such hooks which provide either a mechanism for other modules to react to events within a specific module's functionality, or to inject functionality of their own.

The hook system allows modules to affect functionality of other modules without us having to make changes directly in the programming code of those modules themselves. An introduction to the Drupal hooks system can be found on the Drupal website at http://drupal.org/node/292. We may also visit http://drupal.org/node/361112 to obtain detailed information on how to create modules for Drupal 7.

Perhaps most importantly, we should clearly understand why we do not hack core (http://drupal.org/best-practices/do-not-hack-core). Note that the principle of refraining from hacking core is applicable to Drupal core code as well as contributed modules. It is better, by far, to either implement a custom module as we will in the following exercises, or to submit a patch to the relevant module's issue queue if we cannot achieve our goals with a custom module.

The exercises in this chapter, aimed primarily at developers, will reveal how our custom modules may interact with Webform in the context of submissions, for example, when a visitor to our Speaker Registration Webform clicks on the Submit button. We shall also discover how to extend the Webform Validation module by adding our very own validation processing.

We will find several references being made to previous chapters and exercises as we discuss the exercises in this chapter. The adventurous among us who have arrived here without following the sequential development of our sample Speaker Registration form should refer back to previous content as indicated to fully grasp the context of the discussions.

The focus in these exercises is on utilizing the Drupal hook system, thus we will not delve into the intricacies of the PHP programming language as contained in the exercises. The code snippets have been written in a manner promoting readability, as opposed to being optimized for efficiency and terseness, so the lack of detail should not be a hindrance.

Our sites/all/modules/webform folder contains a file called webform_hooks.php. This file documents the collection of hooks that Webform makes available and is a great reference to have handy as we tackle the following exercises.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset