I have created a "Share update" form using form API. Below the form, I am displaying a view "feeds" of all the published nodes of content type "updates". On submit, the form saves the data entered in the form as a node of content type "updates". It reloads the page and displays the recently saved node in the view below the form.
I want the node to appear in the view list without page reload. How to do that?
My form API code looks like this -
function add_update_page($form, &$form_state) {
$form = array(
'#prefix' => '<div id="update-div">',
'#suffix' => '</div>',
'#title' => t('Latest update:'),
'#description' => t('Add status update'),
);
$form['update'] = array(
'#title' => t('Share an update...'),
'#type' => 'textarea',
'#resizable' => '0',
'#format' => 'update_feed_text',
'#label' => t('Share an update...'),
);
$form['submit'] = array(
'#id' => 'update-submit-button',
'#type' => 'submit',
'#default_value' => t('Share'),
);
return $form;
}
function add_update_page_submit($form, &$form_state) {
$update = $form_state['values']['update'];
$node = new stdClass();
$node->type = 'updates';
node_object_prepare($node);
$node->status = 1;
$node->uid = $GLOBALS['user']->uid;
$node->language = LANGUAGE_NONE;
$node->created = time();
$node->changed = $node->created;
$node->title = 'Automatic status update';
$node->body[$node->language][0]['value'] = $form_state['values']['update'];
$node->body[$node->language][0]['summary'] = "";
$node->body[$node->language][0]['format'] = 'filtered_html';
node_save($node);
drupal_set_message($form_state['values']['update']);
$form_state['redirect'] = '<front>';
}
I have looked up everywhere, but the proposed solutions are incomplete, making it harder to follow the logic.