You are here

function cloud_zoom_admin_preset_edit_form_validate in Cloud Zoom 6

Validate handler for the above form

File

./cloud_zoom.admin.inc, line 253
This file contains al the admin-only function

Code

function cloud_zoom_admin_preset_edit_form_validate(&$form, &$form_state) {

  // Do not validate the name if it is not set
  if (!isset($form_state['values']['preset']['name'])) {
    return;
  }

  // Get the name out for easier reference
  $name = $form_state['values']['preset']['name'];

  // If the name contains any non a-z, 0-9 and underscore characters then set an error and return (dont bother checking anything else)
  if (preg_match('/[^a-z0-9_]/', $name)) {
    form_set_error('name', t('Only use lowercase a-z, 0-9 and hyphens.'));
    return;
  }

  // If the name is a valid name AND different to the original preset name,
  // lets check it's not already used
  if (isset($form['#original_preset']) && $form['#original_preset']['name'] != $name) {
    if (cloud_zoom_get_settings($name)) {
      form_set_error('name', t('The preset @name already exists', array(
        '@name' => $name,
      )));
    }
  }
}