Hi,
If you want to forbid user from duplicate name entries creation, this code should help you - data validation in form processing using QuickForm and QFfield.
class some_classCommon extends ModuleCommon {
............
............
public static function check_group_name_exists($name,$id) {
if(isset($id)) { //existing records
$ret = Utils_RecordBrowserCommon::get_records('groups_table', array('group_name'=>$name, '!id'=>$id));
} else { //new records
$ret = Utils_RecordBrowserCommon::get_records('groups_table', array('group_name'=>$name));
}
return empty($ret);
}
public function QFfield_group_name(&$form, $field, $label, $mode, $default, $desc, $rb_obj) {
if ($mode!='view') {
$form->addElement('text', $field, $label, $opts, array('id'=>$field));
$form->registerRule('unique','callback','check_group_name_exists', 'some_classCommon');
$form->addRule($field,$this->t('Group with this name already exists'),'unique',$rb_obj->record['id']);
$form->setDefaults(array($field=>$default));
} else {
$form->addElement('static', $field, $label, $default);
}
}
}
Arek and Janusz told you about processing method - this is where you should trigger exception when creating duplicate entry using Utils_RecordBrowserCommon::new_record method - you should check for duplicates using standard "select" sql query (yes, we know, that some concurrent transaction can modify this table and mess up everything, but as you know, there is no native support for unique keys in RB).
You can catch exception with
try {
Utils_RecordBrowserCommon::new_record('some_table',array(............));
} ...
Cheers
Paul