You are here

function homebox_check_name in Homebox 6.2

Same name and namespace in other branches
  1. 6.3 homebox.module \homebox_check_name()
  2. 7.3 homebox.module \homebox_check_name()
  3. 7.2 homebox.module \homebox_check_name()

Validation helper function for page name

Parameters

$name: The name to be tested for the page

$element: Optional, the form element identifier to throw form errors

Return value

TRUE if name is valid to use, otherwise, FALSE.

2 calls to homebox_check_name()
homebox_admin_page_validate in ./homebox.admin.inc
homebox_check_page_object in ./homebox.module
Validation helper to check a page object

File

./homebox.module, line 925
Homebox main file, takes care of global functions settings constants, etc.

Code

function homebox_check_name($name, $element = NULL) {

  // Ensure name fits the rules:
  if (preg_match('/[^a-z0-9_]/', $name)) {
    if ($element) {
      form_set_error($element, t('Machine name must be lowercase alphanumeric or underscores only.'));
    }
    return FALSE;
  }

  // Check for name dupes
  if (db_result(db_query("SELECT COUNT(*) FROM {homebox_pages} WHERE name = '%s'", $name))) {
    if ($element) {
      form_set_error($element, t('The page name %name already exists. Please choose another page name.', array(
        '%name' => $name,
      )));
    }
    return FALSE;
  }
  return TRUE;
}