Hi,
I'm overriding my form submit so it saves a taxonomy tid I send through as a value from the form, and so I can change the drupal message. I think I'm doing something wrong though as it works on a vanilla site but not on my live site. Can anyone tell me whether this is affecting the AJAX at all?
/**
* Implementation of hook_form_submit().
*
* Save the node and the taxonomy tid passed through from the form
*/
function company_questions_form_submit($form, &$form_state) {
global $user;
$node = node_form_submit_build_node($form, $form_state);
$insert = empty($node->nid);
// Get our Company Questions vid
$vid = variable_get('company_questions_vocabulary', 0);
// Get the term tid we passed through from our form
$tid = $form_state['values']['taxonomy_tid'];
// Add into the taxonomy of the node before we save it
$node->taxonomy[$vid][$tid] = $tid;
$node->taxonomy = array($vid => array($tid => $tid));
node_save($node);
taxonomy_node_save($node,array($vid => array($tid => $tid)));
$node_link = l(t('view'), 'node/'. $node->nid);
$watchdog_args = array('@type' => $node->type, '%title' => $node->title, '%tid' => $tid);
$t_args = array('@type' => node_get_types('name', $node), '%title' => $node->title);
if ($insert) {
watchdog('content', '@type: added %title with tid %tid.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
drupal_set_message(t(variable_get('company_questions_submit_message', 'Thanks!')));
}
else {
watchdog('content', '@type: updated %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
drupal_set_message(t('@type %title has been updated.', $t_args));
}
if ($node->nid) {
unset($form_state['rebuild']);
$form_state['nid'] = $node->nid;
$form_state['redirect'] = 'node/'. $node->nid;
}
else {
// In the unlikely case something went wrong on save, the node will be
// rebuilt and node form redisplayed the same way as in preview.
drupal_set_message(t('The question could not be saved.'), 'error');
}
}
/**
* Implementation of hook_form_alter().
*
*/
function company_questions_form_company_question_node_form_alter (&$form, &$form_state) {
if (arg(2) != 'edit') {
$form['#action'] = url('node/add/company-question');
}
}
thx...