User is allowed to submit answers from the question node view page.
The form is redirected to the same question node view page after submission. But the form displayed still displays the older values. How can I reset these values?
function answers_custom_node_view($node, $view_mode, $langcode) {
if (arg(0) == 'node' && is_numeric(arg(1)) && $node->type == 'question') {
global $user;
if(node_access("create", "answer", $user)) {
$node1 = (object) array(
'uid' => $user->uid,
'name' => (isset($user->name) ? $user->name : ''),
'type' => "answer",
'language' => LANGUAGE_NONE,
);
$form_state['build_info']['args'] = array($node1);
form_load_include($form_state, 'inc', 'node', 'node.pages');
$form = drupal_build_form('answer_node_form', $form_state);
$output = drupal_render($form);
$node->content['answer_form'] = array(
"#type" => "markup",
"#markup" => $output,
);
}
}
}
function answers_custom_form_alter(&$form, &$form_state, $form_id) {
if($form_id == "answer_node_form") {
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
$node = node_load($nid);
if($node->type == "question") {
$form['#submit'][] = "answers_custom_destination";
}
}
}
}
function answers_custom_destination($form, &$form_state){
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
$node = node_load($nid);
if($node->type == "question") {
$form_state['rebuild'] = TRUE;
$form_state['redirect'] = drupal_get_path_alias('node/'. $node->nid);
}
}
}