I am trying to update a value during the validate phase of a node form: When the custom validation error is fired, I empty one of the fields.
I am trying to use the following code.
function eventcheck_node_validate($node, $form, &$form_state) {
if ($node->type == 'article') {
if ((array_key_exists('endpoints',$node->field_event_choose['und'][0])) && (($node->field_event_title['und'][0]['value']<>'') || (isset($node->field_event['und'][0]['value'])))) {
$form_set_value(???);
$form_set_error('event_checker_group',t('Error message'));
}
}
}
I understand that the last parameter for form_set_value()
is the same $form_state
the validation handler gets. What are the $element
and the $value
?
I was trying a lot and apparently the desired value resides in $form['field_name']['und'][0]['value']['#value']
and only there. When I try form_set_value($form['field_name']['und'][0]['value']['#value'],'foo',$form_state)
, I get this error.
Recoverable fatal error: Argument 2 passed to drupal_array_set_nested_value() must be an array, string given, called in /includes/form.inc on line 2436 and defined in drupal_array_set_nested_value()
I also tried the following code.
$newvalue = $form['field_name']['und'][0]['value'];
$newvalue['#value']='foo';
form_set_value($form['field_name']['und'][0]['value'],$newvalue,$form_state);
I get this error.
Warning: mb_strlen() expects parameter 1 to be string, array given in drupal_strlen()