I have no idea why I cannot find an answer to this. I've been able to do this with other fields except the 'title' field.
I have a form which I need to automatically populate the title field. I don't want the user to populate it, so I'm hiding it by wrapping it in a that's hidden.
I used hook_form_alter() to add a callback function to the form's #submit array, but those functions are called after the validation. This would result in an error telling the user to enter a title.
Now I'm trying to use hook_form_alter and adding a validation callback function to the BEGINNING of the array like so:
function previous_meetings_form_alter(&$form, $form_state, $form_id)
{
//Hide the title field
$form['title']['#prefix'] = '<div style="display: none;">';
$form['title']['#suffix'] = '</div>';
//Callback function to execute before validation
array_unshift($form['#validate'], '_previous_meetings_set_meeting_title');
}
Here is the callback function that is being called but NOT working:
function _previous_meetings_set_meeting_title(&$form, &$form_state)
{
$form_state['values']['title'] = 'SOMETHING';
}
What am I doing wrong? Can I set values in a validation callback? Is there a right approach to this?
Thanks!