You are here

function _webform_edit_phone in Webform Phone Number 7

Same name and namespace in other branches
  1. 7.2 webform_phone.components.inc \_webform_edit_phone()

Generate the form for editing a component. Create a set of form elements 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).

Parameters

$component: A Webform component array.

Return value

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

File

./webform_phone.components.inc, line 57
Webform Component information for a phone number field type

Code

function _webform_edit_phone($component) {
  $form = array();

  // General Options
  $form['extra']['country'] = array(
    '#type' => 'select',
    '#title' => t('Country'),
    '#options' => phone_countries(),
    '#default_value' => $component['extra']['country'],
    '#description' => t('Which country-specific rules should this field be validated against and formatted according to.'),
    '#required' => TRUE,
  );
  $form['extra']['phone_country_code'] = array(
    '#type' => 'checkbox',
    '#title' => t('Add the country code if not filled by the user'),
    '#default_value' => $component['extra']['phone_country_code'],
  );

  // International Options
  $form['extra']['phone_int_help'] = array(
    '#type' => 'markup',
    '#value' => t('International phone numbers are in the form +XX YYYYYYY where XX is a country code and YYYYYYY is the local number. This field type is based off of the <a href="http://www.itu.int/rec/T-REC-E.123/en">E.123 specification</a>.'),
    '#states' => array(
      'visible' => array(
        ':input[name="extra[country]"]' => array(
          'value' => 'int',
        ),
      ),
    ),
  );
  $form['extra']['phone_default_country_code'] = array(
    '#type' => 'textfield',
    '#title' => t('Default country code to add to international numbers without one (omit + sign)'),
    '#default_value' => $component['extra']['phone_default_country_code'],
    '#states' => array(
      'visible' => array(
        ':input[name="extra[country]"]' => array(
          'value' => 'int',
        ),
      ),
    ),
  );
  $form['extra']['phone_int_max_length'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum length of international numbers, according to the ITU this is 15'),
    '#default_value' => $component['extra']['phone_int_max_length'],
    '#states' => array(
      'visible' => array(
        ':input[name="extra[country]"]' => array(
          'value' => 'int',
        ),
      ),
    ),
  );

  // US/Canada Options
  $form['extra']['ca_phone_separator'] = array(
    '#type' => 'textfield',
    '#title' => t('Separator'),
    '#default_value' => $component['extra']['ca_phone_separator'],
    '#size' => 2,
    '#states' => array(
      'visible' => array(
        ':input[name="extra[country]"]' => array(
          'value' => 'ca',
        ),
      ),
    ),
  );
  $form['extra']['ca_phone_parentheses'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use parentheses around area code'),
    '#default_value' => $component['extra']['ca_phone_parentheses'],
    '#states' => array(
      'visible' => array(
        ':input[name="extra[country]"]' => array(
          'value' => 'ca',
        ),
      ),
    ),
  );
  $form['value'] = array(
    '#type' => 'textfield',
    '#title' => t('Default value'),
    '#default_value' => $component['value'],
    '#description' => t('The default value of the field.') . theme('webform_token_help'),
    '#size' => 60,
    '#maxlength' => 1024,
    '#weight' => 0,
  );
  $form['display']['width'] = array(
    '#type' => 'textfield',
    '#title' => t('Width'),
    '#default_value' => $component['extra']['width'],
    '#description' => t('Width of the textfield.') . ' ' . t('Leaving blank will use the default size.'),
    '#size' => 5,
    '#maxlength' => 10,
    '#weight' => 0,
    '#parents' => array(
      'extra',
      'width',
    ),
  );
  $form['display']['placeholder'] = array(
    '#type' => 'textfield',
    '#title' => t('Placeholder'),
    '#default_value' => $component['extra']['placeholder'],
    '#description' => t('The text will be shown in the field until the user starts entering a value.'),
    '#weight' => 1,
    '#parents' => array(
      'extra',
      'placeholder',
    ),
  );
  $form['display']['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' => 11,
    '#default_value' => $component['extra']['disabled'],
    '#parents' => array(
      'extra',
      'disabled',
    ),
  );
  return $form;
}