You are here

function _webform_edit_email in Webform 5.2

Same name and namespace in other branches
  1. 5 components/email.inc \_webform_edit_email()
  2. 6.3 components/email.inc \_webform_edit_email()
  3. 6.2 components/email.inc \_webform_edit_email()
  4. 7.4 components/email.inc \_webform_edit_email()
  5. 7.3 components/email.inc \_webform_edit_email()

Create a set of form items to be displayed on the form for editing this component. Use care naming the form items, as this correlates directly to the database schema. The component "Name" and "Description" fields are added to every component type and are not necessary to specify here (although they may be overridden if desired).

Return value

An array of form items to be displayed on the edit component page.

File

components/email.inc, line 39
Webform module email component.

Code

function _webform_edit_email($currfield) {
  $edit_fields['value'] = array(
    '#type' => 'textfield',
    '#title' => t('Default value'),
    '#default_value' => $currfield['value'],
    '#description' => t('The default value of the field.') . theme('webform_token_help'),
    '#size' => 60,
    '#maxlength' => 127,
    '#weight' => 0,
    '#attributes' => $currfield['value'] == '%useremail' && count(form_get_errors()) == 0 ? array(
      'disabled' => TRUE,
    ) : array(),
    '#id' => 'email-value',
  );
  $edit_fields['user_email'] = array(
    '#type' => 'checkbox',
    '#title' => t('User email as default'),
    '#default_value' => $currfield['value'] == '%useremail' ? 1 : 0,
    '#description' => t('Set the default value of this field to the user email, if he/she is logged in.'),
    '#attributes' => array(
      'onclick' => 'getElementById("email-value").value = (this.checked ? "%useremail" : ""); getElementById("email-value").disabled = this.checked;',
    ),
    '#weight' => 0,
    '#validate' => array(
      '_webform_edit_email_validate' => array(),
    ),
  );
  $edit_fields['extra']['width'] = array(
    '#type' => 'textfield',
    '#title' => t('Width'),
    '#default_value' => $currfield['extra']['width'],
    '#description' => t('Width of the textfield.') . ' ' . t('Leaving blank will use the default size.'),
    '#size' => 5,
    '#maxlength' => 10,
  );
  $edit_fields['extra']['email'] = array(
    '#type' => 'checkbox',
    '#title' => t('E-mail a submission copy'),
    '#return_value' => 1,
    '#default_value' => $currfield['extra']['email'],
    '#description' => t('Check this option if this component contains an e-mail address that should get a copy of the submission. Emails are sent individually so other emails will not be shown to the recipient.'),
  );
  $edit_fields['extra']['disabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Disabled'),
    '#return_value' => 1,
    '#description' => t('Make this field non-editable. Useful for setting an unchangeable default value.'),
    '#weight' => 3,
    '#default_value' => $currfield['extra']['disabled'],
  );
  return $edit_fields;
}