You are here

function rules_admin_validate_machine_name in Rules 6

Validate the machine name.

4 calls to rules_admin_validate_machine_name()
rules_admin_form_add_rule_set_validate in rules_admin/rules_admin.sets.inc
Validates the set and builds it -> $form_state['set']
rules_admin_form_add_rule_validate in rules_admin/rules_admin.rule_forms.inc
rules_admin_form_edit_rule_set_validate in rules_admin/rules_admin.sets.inc
rules_admin_form_edit_rule_validate in rules_admin/rules_admin.rule_forms.inc

File

rules_admin/rules_admin.module, line 265
Rules administration UI

Code

function rules_admin_validate_machine_name($item_type, $element_name, $machine_name) {

  // Check that the machine name is valid. We only
  if (!preg_match('/^[a-z][a-z0-9_]*$/', $machine_name)) {
    form_set_error($element_name, t('Machine name must be alphanumeric and underscores only, and the first character must be a lower case letter.'));
    return;
  }

  // Fetch information about table.
  $info = rules_get_items($item_type);

  // Check that the machine name doesn't exist.
  $count = db_result(db_query("SELECT COUNT(*) FROM {" . $info['db_table'] . "} WHERE name = '%s'", 'rules_' . $machine_name));
  if ($count) {
    form_set_error($element_name, t('The given machine name already exists.'));
  }
}