You are here

function nd_code_field_form_validate in Node displays 6

Validate code field submission, only on insert.

File

includes/nd.fields.inc, line 176
Manage fields.

Code

function nd_code_field_form_validate($form, &$form_state) {
  if ($form['#form_type'] == 'insert') {
    $fields = variable_get('nd_fields', array());
    $existing = array_keys($fields);
    if (in_array($form_state['values']['code_key'], $existing)) {
      form_set_error('code_key', t('This field already exists.'));
    }
    if (!preg_match('!^[a-z_]+$!', $form_state['values']['code_key'])) {
      form_set_error('code_key', t('The machine-readable name must contain only lowercase letters and underscores.'));
    }
  }
}