You are here

function panels_page_edit_form_validate in Panels 6.2

Same name and namespace in other branches
  1. 5.2 panels_page/panels_page.admin.inc \panels_page_edit_form_validate()

Validate a panel page edit form.

File

panels_page/panels_page.admin.inc, line 359
panels_page.admin.inc

Code

function panels_page_edit_form_validate($form, &$form_state) {

  // Validate the system name; check for its presence, pass it through a preg
  // filter for allowed characters, and test for uniqueness.
  if (!$form_state['values']['name']) {
    form_error($form['left']['info']['name'], t('Panel name is required.'));
  }
  else {
    if (preg_match("/[^A-Za-z0-9_]/", $form_state['values']['name'])) {
      form_error($form['left']['info']['name'], t('Panel name must be alphanumeric or underscores only.'));
    }
    else {
      if (!preg_match("/[A-Za-z_]/", $form_state['values']['name'])) {
        form_error($form['left']['info']['name'], t('Panel name must not consist exclusively of numbers.'));
      }
      else {
        if (db_result(db_query("SELECT pid FROM {panels_page} WHERE name = '%s' AND pid <> %d", $form_state['values']['name'], $form_state['pid']))) {
          form_error($form['left']['info']['name'], t('Panel name must be unique.'));
        }
      }
    }
  }

  // Validate the path; check for its presence, uniqueness within panels_page,
  // and uniqueness with respect to path aliases.
  if (!$form_state['values']['path']) {
    form_error($form['left']['info']['path'], t('Path is required.'));
  }
  else {
    if ($result = db_result(db_query("SELECT name FROM {panels_page} WHERE path = '%s' AND pid <> %d", $form_state['values']['path'], $form_state['pid']))) {
      form_error($form['left']['info']['path'], t("'Path' must be unique among Panels Page paths. The path '@path' is currently in owned by '@name'.", array(
        '@path' => $form_state['values']['path'],
        '@name' => $result,
      )));
    }
    if (db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $form_state['values']['path']))) {
      form_error($form['left']['info']['path'], t('The path you have chosen is already aliased to @src.', array(
        '@src' => $result,
      )));
    }
  }
}