Setting the form value to an organic group gid from validation hook of custom field widget (Drupal 7)
I'm assuming the validate callback that you have mentioned in your question is the #element_validate callback for the field widget element.

In that case, form_set_value must be set to a list of items because a field is inherently multi-valued. Each item in this list must conform to the schema of the field.

So, in this case:

$items = array();
$delta = 0;
$gid = ...; // From somewhere
$items[$delta] = array(
  'gid' =&gt; $gid,
  'state' =&gt; OG_STATE_ACTIVE, // optional
  'created' =&gt; REQUEST_TIME - 3600 // optional (yesterday)
);
form_set_value($element, $items, $form_state);


To illustrate this better, I have a sandbox project up on drupal.org. It declares a new widget with hierarchical dropdowns just like you have described. You can check the code directly from http://drupalcode.org/sandbox/amarnus/1868742.git/tree/refs/heads/master or clone the project from http://drupal.org/sandbox/amarnus/1868742. Hope this helps!