You are here

function panels_mini_edit_form_validate in Panels 5.2

Same name and namespace in other branches
  1. 6.2 panels_mini/panels_mini.admin.inc \panels_mini_edit_form_validate()

Validate submission of the mini panel edit form.

File

panels_mini/panels_mini.module, line 554
panels_mini.module

Code

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

  // Test uniqueness of name:
  if (!$form_values['name']) {
    form_error($form['left']['settings']['name'], t('Panel mini name is required.'));
  }
  else {
    if (preg_match("/[^A-Za-z0-9_]/", $form_values['name'])) {
      form_error($form['left']['settings']['name'], t('Name must be alphanumeric or underscores only.'));
    }
    else {
      if (preg_match("/[^A-Za-z0-9 ]/", $form_values['category'])) {
        form_error($form['left']['settings']['category'], t('Categories may contain only alphanumerics or spaces.'));
      }
      else {
        $query = "SELECT pid FROM {panels_mini} WHERE name = '%s'";
        if (!empty($form_values['pid']) && is_numeric($form_values['pid'])) {
          $query .= " AND pid != {$form_values['pid']}";
        }
        if (db_result(db_query($query, $form_values['name']))) {
          form_error($form['left']['settings']['name'], t('Panel name must be unique.'));
        }
      }
    }
  }
}