I'm going slowly and quietly mad here. Any advice would be greatly appreciated.
This concerns form processing on the node_form for a particular content type.
I have a rather peculiar use case to satisfy.
I have a content type in which I have a node reference field. The logic I need to enact is:
// PLEASE NOTE THIS IS PSEUDO-CODE, NOT INTENDED AS LITERAL CODE
// ---------------------------------------------------------------------------
if( empty(node->title) ){
if( ! empty(node->node_reference_field_nid) ){
$title = get the title of the referred node
node->title = $title;
else{
form_set_error('title', 'you have to give me either a title or a node_reference');
}
}I am trying to do this in my validate function. As follows:MYMOD_contenttype_node_form_validate(&$form_state, &$form, $form_id) (Call by reference on the first two vars).
And I have prepended my validate function to the form's #validate array, so presumably it fires first.
So far, I have had to set $form['title']['#required'] = FALSE; in my form_alter to do this.
I have tried testing with:form_set_value($form['title'], "This is a test value", $form_state);
and$form_state['values']['title'] = "This is a test value";
and with and without$form_state['rebuild'] = TRUE;
Nothing seems to work. If I don't do a form_set_error to stop the processing I end up with a node that has no title.
There HAS to be some way to make this work.
Any advice would be much appreciated.
Thanks for reading.
Comments
RESOLVED
MYMOD_contenttype_node_form_validate(&$form_state, &$form, $form_id)Should have been:
MYMOD_contenttype_node_form_validate(&$form, &$form_state, $form_id)