You are here

function webform_validation_manage_rule in Webform Validation 6

Same name and namespace in other branches
  1. 7 webform_validation.admin.inc \webform_validation_manage_rule()
1 string reference to 'webform_validation_manage_rule'
webform_validation_menu in ./webform_validation.module
Implementation of hook_menu().

File

./webform_validation.admin.inc, line 72
Manages validation rules administration UI

Code

function webform_validation_manage_rule($form_state, $node, $action = 'add', $validator, $rule = NULL) {
  $form = array();
  $rule_validator = webform_validation_get_validator_info($validator);
  $form['rule'] = array(
    '#type' => 'fieldset',
    '#title' => $action == 'edit' ? t('Edit rule') : t('Add rule'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
  );
  $form['rule']['validator'] = array(
    '#type' => 'hidden',
    '#value' => $validator,
  );
  $form['rule']['action'] = array(
    '#type' => 'hidden',
    '#value' => $action,
  );
  if ($action == 'edit' && $rule) {
    $form['rule']['ruleid'] = array(
      '#type' => 'hidden',
      '#value' => $rule['ruleid'],
    );
    $form['rule']['nid'] = array(
      '#type' => 'hidden',
      '#value' => $rule['nid'],
    );
  }
  else {
    $form['rule']['nid'] = array(
      '#type' => 'hidden',
      '#value' => $node->nid,
    );
  }
  $form['rule']['rulename'] = array(
    '#type' => 'textfield',
    '#title' => t('Rule name'),
    '#default_value' => isset($rule['rulename']) ? $rule['rulename'] : '',
    '#required' => TRUE,
    '#size' => 60,
    '#maxlength' => 255,
    '#weight' => 1,
  );
  $form['rule']['rule_components'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Components'),
    '#weight' => 3,
    '#description' => t('Select the components to be validated by this validation rule'),
    '#options' => webform_validation_get_webform_components($node, $validator),
    '#default_value' => isset($rule['components']) ? array_keys($rule['components']) : array(),
  );
  if (isset($rule_validator['custom_data']) && is_array($rule_validator['custom_data'])) {
    $required = isset($rule_validator['custom_data']['required']) ? $rule_validator['custom_data']['required'] : TRUE;
    $form['rule']['data'] = array(
      '#type' => 'textfield',
      '#title' => $rule_validator['custom_data']['label'],
      '#description' => $rule_validator['custom_data']['description'],
      '#required' => $required !== FALSE ? TRUE : FALSE,
      '#size' => 60,
      '#maxlength' => 255,
      '#default_value' => $rule['data'],
      '#weight' => 4,
    );
  }
  if (isset($rule_validator['custom_error'])) {
    $form['rule']['error_message'] = array(
      '#type' => 'textfield',
      '#title' => t('Custom error message'),
      '#description' => t("Specify an error message that should be displayed when user input doesn't pass validation"),
      '#required' => TRUE,
      '#size' => 60,
      '#maxlength' => 255,
      '#default_value' => $rule['error_message'],
      '#weight' => 5,
    );
  }
  $form['rule']['submit'] = array(
    '#type' => 'submit',
    '#value' => isset($rule['ruleid']) ? t('Save rule') : t('Add rule'),
    '#weight' => 25,
  );
  return $form;
}