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])) {

Custom coding: Advanced Webform Confirmation Pages

In 3.x and newer versions of Webform, the use of PHP validation and processing is deprecated because it's unsafe, but you can do whatever you need to within a custom module. Here are the most important parts you'll need for your module to communicate with your webform and validate or process the data available to webform.

In this example, I have a webform that allows visitors to register for an event. After the user submits the form, it they receive a confirmation page that uses some of the submitted data. It prints an ID and sends an email with the same information. I'll be using the 7.x version for this example but if you know how to code, you'll have no problems downgrading to 6.x-3.x

The first step is to create a hook_menu with the callback to hold the confirmation page:

<?php
function reg_menu() {
  	$items['register/confirmation/%/%'] = array(
		'page callback' => 'reg_confirmation_page',
		'page arguments' => array(2, 3),
		'access arguments' => array("access content"),
		'type' => MENU_CALLBACK,
		'title' => 'Confirmation',
	);

        return $items;
}

?>
Subscribe with RSS Subscribe to RSS - Custom coding