Closed (fixed)
Project:
Drupal core
Version:
7.14
Component:
forms system
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
3 May 2012 at 12:25 UTC
Updated:
10 Oct 2013 at 13:45 UTC
I am trying to rebuild a form in Drupal 7. I know its 'form_build_id' (e.g. form-_eNZLqaZWy7-6kYuGma5Cxg1Gru7Tmr9W2tsofSJxSg)
I defined this hook_menu and menu callback function:
/**
* Implements hook_menu().
*/
function set_menu_menu() {
$items['admin/structure/set_menu/rebuild/%'] = array(
'title' => 'Rebuilt',
'page callback' => 'set_menu_ajax_rebuild',
'page arguments' => array(4),
'access callback' => TRUE,
);
return $items;
}
function set_menu_ajax_rebuild($form_build_id) {
$form_state = form_state_defaults();
$form = form_get_cache($form_build_id, $form_state);
$form_state['no_redirect'] = TRUE;
// @see drupal_rebuild_form()
// I would like to increase number of elements in my form
$form_state['set_menu']['count']++;
$form_state['rebuild'] = TRUE;
drupal_process_form($form['#form_id'], $form, $form_state);
}
I would like to rebuild a form by hitting url like this http://www.example.com/admin/structure/set_menu/rebuild/form-mQVd8FeimUA... - this url displays no error but it does not rebuild my form.
The code never rebuilds any form. Is it possible to rebuild a form this way?
Thank you, Martin.
Comments
Comment #1
pasqualleit seems like your code is based on old D6 way of doing ajax in forms, in D7 it is much more easier.
check the ajax examples in https://drupal.org/project/examples