Unique id in field
Permalink
I am developing an add-on for a client and in one of the fields I need it to be a unique integer.
Dow can I specify that the column is unique in the table and confirm on save that the value is unique otherwise provide an error to the user.
Is it possible to ensure the field on the form only accepts values like 1, 203, 999 etc. No value below zero.
Dow can I specify that the column is unique in the table and confirm on save that the value is unique otherwise provide an error to the user.
Is it possible to ensure the field on the form only accepts values like 1, 203, 999 etc. No value below zero.
I am saving to a database table. I need to check the frontend value from the form and conform it is not in the database table. If present in the database table inform the user of a duplicate value.
How about something like this:
$app = Application::getFacadeApplication(); $db = $app->make('database')->connection(); $q = 'SELECT column_name FROM table_name WHERE column_name = ?'; $v = [$variable_value]; $fetched_value = $db->fetchColumn($q, $v); if (!empty($fetched_value)) { ... }
Do you need to check input values in front end or back end or both?