You are here

function panels_page_edit_form_validate in Panels 5.2

Same name and namespace in other branches
  1. 6.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 333
panels_page.admin.inc

Code

function panels_page_edit_form_validate($form_id, $form_values, $form) {

  // Validate the system name; check for its presence, pass it through a preg
  // filter for allowed characters, and test for uniqueness.
  if (!$form_values['name']) {
    form_error($form['left']['info']['name'], t('Panel name is required.'));
  }
  else {
    if (preg_match("/[^A-Za-z0-9_]/", $form_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_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_values['name'], $form_values['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_values['path']) {
    form_error($form['left']['info']['path'], t('Path is required.'));
  }
  else {
    if ($result = db_result(db_query("SELECT pid FROM {panels_page} WHERE path = '%s' AND pid <> %d", $form_values['path'], $form_values['pid']))) {
      form_error($form['left']['info']['path'], t('Path may not be the same as another panel page path.'));
    }
    if (db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $form_values['path']))) {
      form_error($form['left']['info']['path'], t('The path you have chosen is already aliased to @src.', array(
        '@src' => $result,
      )));
    }
  }
}