esign_webform.module in E-Sign 7
Defines all hooks and functions to manage the e-sign field for webforms.
This is for Webforms only.
File
esign_webform/esign_webform.moduleView source
<?php
/**
* @file
* Defines all hooks and functions to manage the e-sign field for webforms.
*
* This is for Webforms only.
*/
/**
* Implements hook_webform_component_info().
*/
function esign_webform_webform_component_info() {
$components = array();
$components['esign'] = array(
'label' => t('E-Sign'),
'description' => t('An E-Signature field'),
'features' => array(
'csv' => TRUE,
'email' => TRUE,
'email_address' => FALSE,
'email_name' => FALSE,
'required' => TRUE,
'conditional' => TRUE,
'title_display' => TRUE,
'title_inline' => FALSE,
'private' => TRUE,
'group' => FALSE,
'spam_analysis' => FALSE,
'attachment' => FALSE,
),
);
return $components;
}
/**
* Implements _webform_defaults_component().
*/
function _webform_defaults_esign() {
return array(
'name' => '',
'form_key' => NULL,
'pid' => 0,
'weight' => 0,
'value' => '',
'mandatory' => TRUE,
'extra' => array(
'title_display' => 0,
'private' => FALSE,
'field_prefix' => '',
'field_suffix' => '',
'description' => '',
'hide_name' => FALSE,
'hide_title' => FALSE,
),
);
}
/**
* Implements _webform_edit_component().
*/
function _webform_edit_esign($component) {
$form = array();
$form['value'] = array(
'#type' => 'textfield',
'#title' => t('Default Signer Title'),
'#default_value' => $component['value'],
'#description' => t('The default "title" of the signer.'),
'#maxlength' => 255,
);
$form['extra']['hide_name'] = array(
'#type' => 'checkbox',
'#title' => 'Hide Signer Name',
'#default_value' => $component['extra']['hide_name'],
'#description' => t('Hide the Signer Name field that is normally below the signature box.'),
);
$form['extra']['hide_title'] = array(
'#type' => 'checkbox',
'#title' => 'Hide Signer Title',
'#default_value' => $component['extra']['hide_title'],
'#description' => t('Hide the Signer Title field that is normally below the signature box.'),
);
return $form;
}
/**
* Implements _webform_render_component().
*/
function _webform_render_esign($component, $value = NULL, $filter = TRUE) {
$form_item = array(
'#type' => 'esign_signature',
'#field_name' => 'esign_signature_field',
'#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
'#required' => $component['required'],
'#hide_name' => $component['extra']['hide_name'],
'#hide_title' => $component['extra']['hide_title'],
'#weight' => $component['weight'],
'#description' => $filter ? _webform_filter_descriptions($component['extra']['description']) : $component['extra']['description'],
'#default_value' => $filter ? _webform_filter_values($component['value']) : $component['value'],
'#prefix' => '<div class="webform-component-esign" id="webform-component-' . $component['form_key'] . '">',
'#suffix' => '</div>',
'#element_validate' => array(
'esign_webform_validate_esign',
),
);
if (isset($component['value'])) {
$form_item['#default_value'] = array();
$form_item['#default_value']['signer_title'] = $component['value'];
}
if (isset($value)) {
$form_item['#default_value'] = array(
'signer_name' => $value['signer_name'],
'signer_title' => $value['signer_title'],
'esignature' => $value['esignature'],
);
}
return $form_item;
}
/**
* Implements _webform_display_component().
*/
function _webform_display_esign($component, $value, $format = 'html') {
return array(
'#title' => $component['name'],
'#weight' => $component['weight'],
'#theme' => 'webform_display_esign',
'#theme_wrappers' => $format == 'html' ? array(
'webform_element',
) : array(
'webform_element_text',
),
'#post_render' => array(
'webform_element_wrapper',
),
'#field_prefix' => $component['extra']['field_prefix'],
'#field_suffix' => $component['extra']['field_suffix'],
'#component' => $component,
'#format' => $format,
'#value' => isset($value) ? esign_webform_display_format($value) : '',
);
}
/**
* Implements hook_theme().
*/
function _webform_theme_esign() {
return array(
'webform_display_esign' => array(
'render element' => 'element',
),
);
}
/**
* Implements hook_webform_validation_validators().
*/
function esign_webform_webform_validation_validators() {
return array(
'esignature_signed' => array(
'name' => 'Signature Field Signed',
'component_types' => array(
'esign',
),
'custom_error' => TRUE,
'min_components' => 1,
'description' => t('Verifies that the signature field is signed.'),
),
);
}
/**
* Implements hook_webform_validation_validate().
*/
function esign_webform_webform_validation_validate($validator_name, $items, $components, $rule) {
if ($items) {
$errors = array();
switch ($validator_name) {
case 'esignature_signed':
$errors = esign_webform_signature_signed($items, $rule);
return $errors;
}
}
}
/**
* Format the output of data for this component.
*/
function theme_webform_display_esign($variables) {
$element = $variables['element'];
$value = $element['#format'] == 'html' ? $element['#value'] : $element['#value'];
return $value !== '' ? $value : '';
}
/**
* Return the result of a component value for display in a table.
*/
function _webform_table_esign($component, $value) {
$signature = array();
if (isset($value['esignature']) && $value['esignature']) {
$signature[] = t('Signed');
}
else {
$signature[] = t('Not Signed');
}
if (!empty($value['signer_name'])) {
$signature[] = $value['signer_name'];
}
if (!empty($value['signer_title'])) {
$signature[] = $value['signer_title'];
}
if (!empty($value['created'])) {
$signature[] = date('Y-m-d', $value['created']);
}
$signature = array_filter($signature);
$signature = implode(', ', $signature);
return check_plain($signature);
}
/**
* Return the heading for this component to be displayed in a CSV file.
*/
function _webform_csv_headers_esign($component, $export_options) {
$header = array();
$header[0] = '';
$header[1] = '';
$header[2] = array(
t('@signature Status', array(
'@signature' => $component['name'],
)),
t('@signature Name', array(
'@signature' => $component['name'],
)),
t('@signature Title', array(
'@signature' => $component['name'],
)),
t('@signature Date', array(
'@signature' => $component['name'],
)),
);
return $header;
}
/**
* Format the submitted data of a component for CSV downloading.
*/
function _webform_csv_data_esign($component, $export_options, $value) {
$signature = array();
if (isset($value['esignature']) && $value['esignature']) {
$signature[] = t('Signed');
}
else {
$signature[] = t('Not Signed');
}
if (!empty($value['signer_name'])) {
$signature[] = $value['signer_name'];
}
else {
$signature[] = t('[BLANK]');
}
if (!empty($value['signer_title'])) {
$signature[] = $value['signer_title'];
}
else {
$signature[] = t('[BLANK]');
}
if (!empty($value['created'])) {
$signature[] = date('Y-m-d', $value['created']);
}
else {
$signature[] = t('[BLANK]');
}
return $signature;
}
/**
* Format esign component data to display as 12345678-123456-1.
*/
function esign_webform_display_format($value) {
$signer_name = '';
$signer_title = '';
if (isset($value['signer_name'])) {
$signer_name = $value['signer_name'];
}
if (isset($value['signer_title'])) {
$signer_title = $value['signer_title'];
}
$value = t('<div class="esignature"><img src="@signature" alt="@signer_name" /></div><div class="signer_name">@signer_name</div><div class="signer_title">@signer_title</div><div class="created">@created</div><br/>', array(
'@signature' => $value['esignature'],
'@signer_name' => $signer_name,
'@signer_title' => $signer_title,
'@created' => format_date($value['created']),
));
return $value;
}
/**
* Form API Validation function to validate the esignature.
*/
function esign_webform_signature_signed($items, $rule) {
$errors = array();
foreach ($items as $key => $value) {
if (!$value['esignature']) {
$errors[$key] = _webform_validation_i18n_error_message($rule);
}
}
return $errors;
}
/**
* Form API Validation function to validate the esignature.
*/
function esign_webform_validate_esign($form_element, &$form_state) {
$error = FALSE;
if ($form_element['#required'] && !$form_element['#value']['esignature']) {
$error = TRUE;
form_error($form_element, t('A signature is required.'));
}
return $error;
}
Functions
Name![]() |
Description |
---|---|
esign_webform_display_format | Format esign component data to display as 12345678-123456-1. |
esign_webform_signature_signed | Form API Validation function to validate the esignature. |
esign_webform_validate_esign | Form API Validation function to validate the esignature. |
esign_webform_webform_component_info | Implements hook_webform_component_info(). |
esign_webform_webform_validation_validate | Implements hook_webform_validation_validate(). |
esign_webform_webform_validation_validators | Implements hook_webform_validation_validators(). |
theme_webform_display_esign | Format the output of data for this component. |
_webform_csv_data_esign | Format the submitted data of a component for CSV downloading. |
_webform_csv_headers_esign | Return the heading for this component to be displayed in a CSV file. |
_webform_defaults_esign | Implements _webform_defaults_component(). |
_webform_display_esign | Implements _webform_display_component(). |
_webform_edit_esign | Implements _webform_edit_component(). |
_webform_render_esign | Implements _webform_render_component(). |
_webform_table_esign | Return the result of a component value for display in a table. |
_webform_theme_esign | Implements hook_theme(). |