Skip to content
Snippets Groups Projects
Commit 2ff024e2 authored by Jonas Adrian Rieling's avatar Jonas Adrian Rieling
Browse files

added validation for rorid entries

parent 22a852d1
No related branches found
No related tags found
No related merge requests found
......@@ -365,4 +365,14 @@ class WorkingGroup {
);
}
/**
* @param string $rorid
* @return bool
*/
public static function validateRorId($rorid){
return (
preg_match( "/[0-9a-zA-Z]{9}$/", $rorid ) ||
($rorid == 'unknown')
);
}
}
\ No newline at end of file
......@@ -59,6 +59,7 @@ function sfb_commons_config_groups_add(){
'#title' => t('Leader\'s institutions ROR ID'),
'#description' => t('Institutions ROR ID'),
'#default_value' => $working_group->getLeaderInstitution(),
);
$form['leader_orcid'] = array(
'#type' => 'textfield',
......@@ -80,9 +81,13 @@ function sfb_commons_config_groups_add(){
* Validation for group add form.
*/
function sfb_commons_config_groups_add_validate($form, &$form_state){
/** ORCID format validation */
/** format validation */
if(!WorkingGroup::validateORCID($form_state['values']['leader_orcid']))
form_set_error('leader_orcid', t('Give a valid ORCID (e.g. 0000-0000-0000-0000) or leave field with \'unknown\'.'));
if(!WorkingGroup::validateRorId($form_state['values']['leader_institution_ror_id']))
form_set_error('leader_institution_ror_id', t('Give a valid ROR ID (e.g. 021ft0n22) or leave field with \'unknown\'.'));
}
/**
......
......@@ -65,6 +65,7 @@ function sfb_commons_config_groups_edit($form, &$form_state, $working_group_id)
'#title' => t('Leader\'s institutions ROR ID'),
'#description' => t('Institutions ROR ID'),
'#default_value' => $working_group->getLeaderInstitutionRorId(),
];
$form['leader_orcid'] = [
'#type' => 'textfield',
......@@ -151,6 +152,8 @@ function sfb_commons_config_groups_edit_validate($form, &$form_state) {
if(!WorkingGroup::validateORCID($form_state['values']['leader_orcid']))
form_set_error('leader_orcid', t('Give a valid ORCID (e.g. 0000-0000-0000-0000) or leave field with \'unknown\'.'));
if(!WorkingGroup::validateRorId($form_state['values']['leader_institution_ror_id']))
form_set_error('leader_institution_ror_id', t('Give a valid ROR ID (e.g. 021ft0n22) or leave field with \'unknown\'.'));
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment