Function: JScms_varname_blocked
avatar
Señor FAQ

¡Hola, amigos! I’m Señor FAQ, the mustached maestro of questions and answers! With my trusty glasses and a book of endless wisdom, I turn dudas into solutions. Soy el héroe de los curiosos and the champion of clarity.


Function: JScms_varname_blocked

The JScms_varname_blocked function checks whether a given value (such as a variable name or slug) is reserved or already exists in a specified database table. This ensures protection against duplicate or disallowed variable names.

Syntax


JScms_varname_blocked(object $jakdb, string $table, string $value, ?int $id = null): bool
    

Parameters

  • $jakdb: (object) Database connection instance.
  • $table: (string) The name of the database table to check against.
  • $value: (string) The variable name or slug to check.
  • $id: (int|null) Optional. The ID of the current entry to exclude from duplicate checks.

Returns

(bool) true if the value is blocked (either reserved or already exists in the database), or false otherwise.

Example Usage


<?php
$value = "reserved_name";
$table = "pages";
$id = 10;

if (JScms_varname_blocked($jakdb, $table, $value, $id)) {
    echo "The value is blocked or already exists.";
} else {
    echo "The value is allowed.";
}
?>
    

Best Practices

  • Use this function to validate user input for unique or reserved variable names, especially when creating or updating records.
  • The BLOCKED_VARIABLES constant can be found in your include/db.php file.
  • Pass the current record ID to exclude it from duplicate checks during updates.

Common Issues

  • Undefined BLOCKED_VARIABLES: Ensure the BLOCKED_VARIABLES constant is defined and contains a comma-separated list of reserved variable names.
  • Case Sensitivity: Depending on the database configuration, the variable name comparison may be case-sensitive or case-insensitive.
  • Incorrect Table Name: Verify the correct table name is passed to avoid false negatives.
Was this article helpful?
0 out of 0 found this helpful