Hi,<br><br>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?<br>
<br><br>function test_form($form_state) {<br> $form['open'] = array('#value' => '<div id="test_replace">');<br> dpm($form_state);<br> if($form_state['test'] == 1) {<br>
$form['test']['share'] = array(<br> '#type' => 'submit',<br> '#value' => 'share',<br> '#submit' => array('test_form_js_submit'),<br>
'#ahah' => array(<br>
'path' => 'test/js',<br> 'wrapper' => 'test_replace'<br> ));<br> }<br> else {<br> $form['test']['share2'] = array(<br> '#type' => 'submit',<br>
'#value' => 'share2',<br> '#submit' => array('test_form_js_submit'),<br> '#ahah' => array(<br> 'path' => 'test/js',<br> 'wrapper' => 'test_replace'<br>
));<br> }<br> <br> $form['close'] = array('#value' => '</div>');<br> <br> return $form; <br>}<br><br>function test_form_js_submit(&$form, &$form_state) {<br><br> $form_state['test'] = 1 ;<br>
$form_state['rebuild'] = TRUE;<br>}<br><br>function test_form_js() {<br> $form_state = array('submitted' => FALSE);<br> $form_build_id = $_POST['form_build_id'];<br> $form = form_get_cache($form_build_id, $form_state);<br>
$form_state['post'] = $form['#post'] = $_POST;<br> $form['#programmed'] = $form['#redirect'] = FALSE;<br> $args = $form['#parameters'];<br> $form_id = array_shift($args);<br> drupal_process_form($form_id, $form, $form_state);<br>
$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);<br><br> //Get HTML for the replacement form. Only these elements will be AHAH-refreshed.<br> test_add_children($new_form['test'], $form['test']);<br>
$output = theme('status_messages') . drupal_render($new_form);<br> drupal_json(array('status' => TRUE, 'data' => $output));<br>}<br><br>function test_add_children(&$new_form, $form) {<br>
foreach (element_children($form) as $child) {<br> $new_form[$child] = $form[$child];<br> test_add_children($new_form[$child], $form[$child]);<br> }<br>}<br><br>function test_menu() {<br>$items = array();<br><br>
$items['test'] = array(<br>
$items['test/js'] = array(<br> 'page callback' => 'test_form_js',<br> 'type' => MENU_CALLBACK,<br> );<br><br> return $items;<br><br>}<br><br><br>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.<br>
<br clear="all">--<br>Regards,<br>Nitin Kumar Gupta<br><a href="http://publicmind.in/blog/">http://publicmind.in/blog/</a><br>