You are here

function fe_block_machine_name_validate in Features Extra 6

Same name and namespace in other branches
  1. 7 fe_block/fe_block.module \fe_block_machine_name_validate()

Validate machine name.

1 string reference to 'fe_block_machine_name_validate'
fe_block_form_alter in ./fe_block.module
Implementation of hook_form_alter().

File

./fe_block.module, line 370

Code

function fe_block_machine_name_validate($form, &$form_state) {
  if (empty($form_state['values']['machine_name'])) {
    return;
  }
  $table = 'fe_block_boxes';
  if (!preg_match('!^[a-z0-9_]+$!', $form_state['values']['machine_name'])) {
    form_set_error('machine_name', t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
  }
  elseif (db_result(db_query("SELECT COUNT(*) FROM {{$table}} WHERE bid <> %d AND machine_name = '%s'", $form_state['values']['bid'], $form_state['values']['machine_name']))) {
    form_set_error('machine_name', t('The machine-readable name has been taken. Please pick another one.'));
  }
}