Use hook_form_alter to do a entity field query or SQL query to get a list of UIDs that belong to 1 group ... OG may have a function to retrieve that list I dunno.
Once you have a list of UIDs use Devel and dpm($form);
the form object and you can simply unset()
the #options
values for UIDs that dont belong in the OG group. Here's a similar thing I did for limiting to a taxonomy term_reference field to a given level of a nested taxonomy.
If you're paranoid you can also append your own validator function to the form_submit function and cross check that valid UIDs (members in the OG group) are being saved .... but I dont usually bother to do that for intranet sites (I have "trusted" users / staff members ... not joe blow public).
Sample code doing basically the same thing for a taxonomy term reference field.
/**
* Implements hook_form_alter().
*/
function eap_student_videos_form_alter(&$form, &$form_state, $form_id) {
switch ($form_id) {
// Field specific overrides.
case 'eap_studentvideos_node_form':
$form['field_eap_video_country']['#after_build'][] = 'eap_country_term_limit_to_countries';
break;
}
}
function _eap_region_tids() {
return array(24,35,48,8,4);
}
function eap_country_term_limit_to_countries(&$element) {
$options = $element[LANGUAGE_NONE]['#options'];
$result = db_query('
SELECT tth.tid, ttd.name AS term_name
FROM taxonomy_term_hierarchy tth
LEFT JOIN taxonomy_term_data ttd ON tth.tid = ttd.tid
WHERE tth.parent IN (:tids)
ORDER BY 2 ASC
', array(':tids' => _eap_region_tids()));
$country_tids = $result->fetchAllAssoc('tid');
$country_tid_array = array_combine(array_keys($country_tids), array_keys($country_tids));
$new_options = array_intersect_key($options, $country_tid_array);
array_walk($new_options, function(&$value, &$key) { $value = str_replace('-','',$value); });
// array_merge() destroys the array keys.
$new_options = array('_none' => '- Select a value -') + $new_options;
$element[LANGUAGE_NONE]['#options'] = $new_options;
return $element;
}