[development] Question on AHAH

nitin gupta nitingupta.iitg at gmail.com
Fri Apr 2 21:29:02 UTC 2010


Hi,

I have been scratching my head for long, looks like cant figure it out. If I
add elements to the form on an AHAH refresh, let us say a submit button with
AHAH properties, this button will not be submitted using AHAH. Anyone know
about this? any pointers to resources? any work around?


function test_form($form_state) {
  $form['open'] = array('#value' => '<div id="test_replace">');
  dpm($form_state);
  if($form_state['test'] == 1) {
  $form['test']['share'] = array(
    '#type' => 'submit',
        '#value' => 'share',
    '#submit' => array('test_form_js_submit'),
    '#ahah' => array(
      'path' => 'test/js',
      'wrapper' => 'test_replace'
    ));
  }
  else {
      $form['test']['share2'] = array(
    '#type' => 'submit',
    '#value' => 'share2',
    '#submit' => array('test_form_js_submit'),
    '#ahah' => array(
      'path' => 'test/js',
      'wrapper' => 'test_replace'
    ));
  }

  $form['close'] = array('#value' => '</div>');

  return $form;
}

function test_form_js_submit(&$form, &$form_state) {

  $form_state['test'] = 1 ;
  $form_state['rebuild'] = TRUE;
}

function test_form_js() {
  $form_state = array('submitted' => FALSE);
  $form_build_id = $_POST['form_build_id'];
  $form = form_get_cache($form_build_id, $form_state);
  $form_state['post'] = $form['#post'] = $_POST;
  $form['#programmed'] = $form['#redirect'] = FALSE;
  $args = $form['#parameters'];
  $form_id = array_shift($args);
  drupal_process_form($form_id, $form, $form_state);
  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);

  //Get HTML for the replacement form. Only these elements will be
AHAH-refreshed.
  test_add_children($new_form['test'], $form['test']);
  $output = theme('status_messages') . drupal_render($new_form);
  drupal_json(array('status' => TRUE, 'data' => $output));
}

function test_add_children(&$new_form, $form) {
  foreach (element_children($form) as $child) {
    $new_form[$child] = $form[$child];
    test_add_children($new_form[$child], $form[$child]);
  }
}

function test_menu() {
$items = array();

$items['test'] = array(
    $items['test/js'] = array(
    'page callback' => 'test_form_js',
    'type' => MENU_CALLBACK,
  );

  return $items;

}


In the above code, when 'share2' is clicked it submits perfectly using ahah,
and converts to 'share' but this button does not have ahah properties.

--
Regards,
Nitin Kumar Gupta
http://publicmind.in/blog/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20100403/4bb3ee81/attachment.html 


More information about the development mailing list