How to reset form page after it has been successfully submitted? 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' &amp;&amp; is_numeric(arg(1)) &amp;&amp; $node-&gt;type == 'question') {
    global $user;
        if(node_access("create", "answer", $user)) {
        $node1 = (object) array(
            'uid' =&gt; $user-&gt;uid,
            'name' =&gt; (isset($user-&gt;name) ? $user-&gt;name : ''),
            'type' =&gt; "answer",
            'language' =&gt; 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-&gt;content['answer_form'] = array(
            "#type" =&gt; "markup",
            "#markup" =&gt; $output,
        );
      }
   }
}

function answers_custom_form_alter(&amp;$form, &amp;$form_state, $form_id) {
   if($form_id == "answer_node_form") {
       if (arg(0) == 'node' &amp;&amp; is_numeric(arg(1))) {
        $nid = arg(1);
        $node = node_load($nid);
        if($node-&gt;type == "question") {
             $form['#submit'][] = "answers_custom_destination";
        }
       }
   }
}

function answers_custom_destination($form, &amp;$form_state){
   if (arg(0) == 'node' &amp;&amp; is_numeric(arg(1))) {
    $nid = arg(1);
    $node = node_load($nid);
    if($node-&gt;type == "question") {
        $form_state['rebuild'] = TRUE;
        $form_state['redirect'] = drupal_get_path_alias('node/'. $node-&gt;nid);
     }
   }
}
That happens because you are using $form_state['rebuild'] = TRUE; which is telling Drupal to rebuild the same form, which also mean the form will be repopulated with the last values the users entered. When you then set $form_state['rebuild'] to TRUE, $form_state['redirect'] is ignored, since the user is already redirected to the page containing the form.

The code I would use is the following one.

function answers_custom_form_answer_node_form_alter(&amp;$form, &amp;$form_state) {
  if (arg(0) == 'node' &amp;&amp; is_numeric(arg(1))) {
    // See https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_get_object/7.
    $node = menu_get_object();

    if ($node-&gt;type == "question") {
      $form['#submit'][] = "answers_custom_destination";
    }
  }
}

function answers_custom_destination($form, &amp;$form_state) {
  // Since the form submission handler is added only when the user is seeing node/%node,
  // there is no need to verify that again.
  $form_state['redirect'] = FALSE;
}


As side note, since the form alter hooks and the form submission handlers share $form_state, which is passed by reference, if something needs to be shared between those functions, it can be added to $form_state. As long as the added array index doesn't conflict with an array index used by Drupal or third-party modules, all is fine.

For example, this code would use $form_state to share a value between the hook altering the form, and the form submission handler. 

function answers_custom_form_answer_node_form_alter(&amp;$form, &amp;$form_state) {
  if (arg(0) == 'node' &amp;&amp; is_numeric(arg(1))) {
    // See https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_get_object/7.
    $node = menu_get_object();

    if ($node-&gt;type == "question") {
      $form_state['answers_custom_question'] = $node;
      $form['#submit'][] = "answers_custom_destination";
    }
  }
}

function answers_custom_destination($form, &amp;$form_state) {
  // Since the form submission handler is added only when the user is seeing node/%node,
  // there is no need to verify that again.
  $form_state['redirect'] = drupal_get_path_alias('node/' . $form_state['answers_custom_question']-&gt;nid);
}


Reference


drupal_build_form()
drupal_redirect_form()