SproutCMS

This is the code documentation for the SproutCMS project

function uniqueValue()

Checks that a unique value doesn't already exist in the database, e.g. a username or email address.
This is to give a friendlier frontend to DB errors pertaining to UNIQUE constraints.
N.B. this function uses LIKE for case-insensitive matching, so it's even stricter than a UNIQUE constraint.

Usage

void Validity::uniqueValue ( string $val , string $table , string $column [, int $id [, string $error_msg ]] );

Example

$valid->check('email', 'Validity::uniqueValue', 'users', 'email', UserAuth::get_id())

Example

$valid->check('code', 'Validity::uniqueValue', 'events', 'code')

Arguments

  1. string $val
    Value to check
  2. string $table
    Table to search for an extant matching value
  3. string $column
    Column in specified table
  4. int $id = 0
    The ID of the record being edited (0 if adding a new record). This prevents an exception being
           thrown when the record being edited itself is found.
  5. string $error_msg = ''
    Error message to be included in the exception

Exceptions thrown

Return value

  • void