You are here

function clientside_validation_testswarm_fapi_validation in Clientside Validation 7

Same name and namespace in other branches
  1. 7.2 clientside_validation_testswarm/clientside_validation_testswarm.forms.inc \clientside_validation_testswarm_fapi_validation()

Form callback for fapi elements with fapi_validation rules.

1 string reference to 'clientside_validation_testswarm_fapi_validation'
clientside_validation_testswarm_menu in clientside_validation_testswarm/clientside_validation_testswarm.module
Implements hook_menu().

File

clientside_validation_testswarm/clientside_validation_testswarm.forms.inc, line 192

Code

function clientside_validation_testswarm_fapi_validation($form, &$form_state) {
  $form['info'] = array(
    '#markup' => '<p><strong>' . t('Clientside Validation Testswarm - FAPI Validation') . '</strong></p>',
  );
  $form['numeric'] = array(
    '#type' => 'textfield',
    '#title' => t('Numeric'),
    '#description' => t('Numeric values only'),
    '#required' => TRUE,
    '#rules' => array(
      'numeric',
    ),
  );
  $form['length_range'] = array(
    '#type' => 'textfield',
    '#title' => t('Range length'),
    '#description' => t('Enter text - 10 characters maximum, 5 minimum'),
    '#required' => TRUE,
    '#rules' => array(
      'length[5, 10]',
    ),
  );
  $form['chars'] = array(
    '#type' => 'textfield',
    '#title' => t('Chars'),
    '#description' => t('Enter text - only use charachters a, b and c'),
    '#required' => TRUE,
    '#rules' => array(
      'chars[a, b, c]',
    ),
  );
  $form['email'] = array(
    '#type' => 'textfield',
    '#title' => t('Email'),
    '#description' => t('Enter a valid email address'),
    '#required' => TRUE,
    '#rules' => array(
      'email',
    ),
  );
  $form['url'] = array(
    '#type' => 'textfield',
    '#title' => t('URL'),
    '#description' => t('Enter a valid url'),
    '#required' => TRUE,
    '#rules' => array(
      'url',
    ),
  );
  $form['ipv4'] = array(
    '#type' => 'textfield',
    '#title' => t('IPv4'),
    '#description' => t('Enter a valid IPv4 IP'),
    '#required' => TRUE,
    '#rules' => array(
      'ipv4',
    ),
  );
  $form['alpha_numeric'] = array(
    '#type' => 'textfield',
    '#title' => t('Alpha Numeric'),
    '#description' => t('Enter text - alphanumeric characters only'),
    '#required' => TRUE,
    '#rules' => array(
      'alpha_numeric',
    ),
  );
  $form['alpha_dash'] = array(
    '#type' => 'textfield',
    '#title' => t('Alpha dash'),
    '#description' => t('Enter text - alpha characters and dash (-) only'),
    '#required' => TRUE,
    '#rules' => array(
      'alpha_dash',
    ),
  );
  $form['digit'] = array(
    '#type' => 'textfield',
    '#title' => t('Digit'),
    '#description' => t('Enter text - digits only (no dots or dashes)'),
    '#required' => TRUE,
    '#rules' => array(
      'digit',
    ),
  );
  $form['decimal_limited'] = array(
    '#type' => 'textfield',
    '#title' => t('Decimal (limited)'),
    '#description' => t('Enter text - valid decimal value, 2 digits, 3 decimals'),
    '#required' => TRUE,
    '#rules' => array(
      'decimal[2, 3]',
    ),
  );
  $form['regex'] = array(
    '#type' => 'textfield',
    '#title' => t('Regex'),
    '#description' => t('Enter text - machine_name (alphanumeric and underscores)'),
    '#required' => TRUE,
    '#rules' => array(
      'regexp[/^[a-z0-9_]+$/]',
    ),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Send'),
    '#weight' => 100,
  );
  return $form;
}