<div>Hi,</div><div><br></div><div>I was working on this module where I needed to change the submit actions of a submit button, after the submit action of another button. Let us say, I have two submit buttons, sb1 and sb2:</div>
<div><br></div><div><div>$form['sb1'] = array(</div><div> '#type' => 'submit',</div><div> '#value' => t('sb1'),</div><div> '#submit' => array('test_module_sb1_submit'), </div>
<div> );</div><div><br></div><div><div>$form['sb2'] = array(</div><div> '#type' => 'submit',</div><div> '#value' => t('sb2'),</div><div> '#submit' => array('test_module_sb2_submit'), </div>
<div> );</div><div> </div><div> $form['sb2']['#ahah'] = array(</div><div> 'path' => 'test_module/js',</div><div> 'wrapper' => 'test_module_replace',</div>
<div> 'effect' => 'fade',</div><div> );</div><div><br></div><div><br></div><div>Now when sb1 is submitted and form is rebuild, I am changing the submit actions of sb2 to these, </div><div><br></div>
<div><div>$form['sb2'] = array(</div><div> '#type' => 'submit',</div><div> '#value' => t('sb2'),</div><div> '#submit' => array('test_module_sb2_change_submit'), </div>
<div> );</div><div> </div><div> $form['sb2']['#ahah'] = array(</div><div> 'path' => 'test_module_change/js',</div><div> 'wrapper' => 'test_module_replace',</div>
<div> 'effect' => 'fade',</div><div> );</div><div><br></div><div>The submit function is successfully changed to 'test_module_sb2_change_submit', but the '#ahah' property of 'sb2' remains the same. Is this the expected behavior or a bug? I could not find any documentation on this. How this can be achieved? How this can be achieved if the first button 'sb1' is also 'ahah' processed?</div>
<div><br></div><div>Thanks, I am attaching the test code for quick look on what I expect and what I get.</div><div><br></div><div>test_module.module</div><div>------------------------------</div><div><br></div><div><div>
<?php</div>
<div><br></div><div>function test_module_menu() {</div><div><br></div><div>$items = array();</div><div><br></div><div>$items['test'] = array(</div><div> 'title' => 'Test form resubmit',</div>
<div> 'page callback' => 'drupal_get_form',</div><div> 'page arguments' => array('test_module_test'),</div><div> 'access arguments' => FALSE,</div><div> 'type' => MENU_CALLBACK,</div>
<div> );</div><div>$items['test_module/js'] = array(</div><div> 'title' => 'Ahah submit',</div><div> 'page callback' => 'test_module_js',</div><div> 'access callback' => '_test_module_access_js',</div>
<div> 'access arguments' => FALSE,</div><div> 'type' => MENU_CALLBACK,</div><div> );</div><div> </div><div> $items['test_module_change/js'] = array(</div><div> 'title' => 'Ahah submit',</div>
<div> 'page callback' => 'test_module_change_js',</div><div> 'access callback' => '_test_module_access_js',</div><div> 'access arguments' => FALSE,</div><div> 'type' => MENU_CALLBACK,</div>
<div> );</div><div> return $items;</div><div>}</div><div><br></div><div>function _test_module_access_js() {</div><div> return TRUE;</div><div>}</div><div><br></div><div>function test_module_test(&$form_state) {</div>
<div><br></div><div> $form['sb1'] = array(</div><div> '#type' => 'submit',</div><div> '#value' => t('SB1'),</div><div> '#submit' => array('test_module_sb1_submit'), </div>
<div> );</div><div> </div><div> $form['val'] = array('#value' => '<div id="test_module_replace"> This is it </div>');</div><div> </div><div> $form['sb2'] = array(</div>
<div> '#type' => 'submit',</div><div> '#value' => t('SB2'),</div><div> '#submit' => array('test_module_sb2_submit'), </div><div> );</div><div> </div>
<div>
$form['sb2']['#ahah'] = array(</div><div> 'path' => 'test_module/js',</div><div> 'wrapper' => 'test_module_replace',</div><div> 'effect' => 'fade',</div>
<div> );</div><div> </div><div> if($form_state['resub']) {</div><div> </div><div> $form['sb2'] = array(</div><div> '#type' => 'submit',</div><div> '#value' => t('SB2'),</div>
<div> '#submit' => array('test_module_sb2_change_submit'), </div><div> );</div><div> </div><div> $form['sb2']['#ahah'] = array(</div><div> 'path' => 'test_module_change/js',</div>
<div> 'wrapper' => 'test_module_replace',</div><div> 'effect' => 'fade',</div><div> );</div><div> </div><div> }</div><div> </div><div> return $form;</div><div>
</div><div> </div><div> </div><div>}</div><div><br></div><div>function test_module_sb1_submit(&$form, &$form_state) {</div><div>$form_state['rebuild'] = TRUE;</div><div>$form_state['resub'] = TRUE;</div>
<div>}</div><div><br></div><div>function test_module_sb2_submit(&$form, &$form_state) {</div><div>drupal_set_message(t("In submit 1"));</div><div>}</div><div><br></div><div>function test_module_sb2_change_submit(&$form, &$form_state) {</div>
<div>drupal_set_message(t("changed to submit 2"));</div><div>}</div><div><br></div><div><br></div><div>function test_module_js() {</div><div><br></div><div> $form_state = array('storage' => NULL, 'submitted' => FALSE);</div>
<div> $form_build_id = $_POST['form_build_id'];</div><div> $form = form_get_cache($form_build_id, $form_state);</div><div> $form_state['post'] = $form['#post'] = $_POST;</div><div> $form['#programmed'] = $form['#redirect'] = FALSE;</div>
<div> $args = $form['#parameters'];</div><div> $form_id = array_shift($args);</div><div> drupal_process_form($form_id, $form, $form_state);</div><div> $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);</div>
<div> //Get HTML for the replacement form. Only these elements will be AHAH-refreshed.</div><div> $new_form = array();</div><div> </div><div> $new_form['element'] = array('#value' => "Addition by submit 1");</div>
<div> $output = theme('status_messages') . drupal_render($new_form);</div><div> //Return the results.</div><div> drupal_json(array('status' => TRUE, 'data' => $output));</div><div><br>
</div><div>}</div><div>function test_module_change_js() {</div><div><br></div><div> $form_state = array('storage' => NULL, 'submitted' => FALSE);</div><div> $form_build_id = $_POST['form_build_id'];</div>
<div> $form = form_get_cache($form_build_id, $form_state);</div><div> $form_state['post'] = $form['#post'] = $_POST;</div><div> $form['#programmed'] = $form['#redirect'] = FALSE;</div><div>
$args = $form['#parameters'];</div><div> $form_id = array_shift($args);</div><div> drupal_process_form($form_id, $form, $form_state);</div><div> $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);</div>
<div> //Get HTML for the replacement form. Only these elements will be AHAH-refreshed.</div><div> $new_form = array();</div><div> </div><div> $new_form['element'] = array('#value' => "Never gets added");</div>
<div> $output = theme('status_messages') . drupal_render($new_form);</div><div> //Return the results.</div><div> drupal_json(array('status' => TRUE, 'data' => $output));</div><div><br>
</div><div>}</div><div><br></div><div><a href="http://test_module.info">test_module.info</a></div><div>-----------------------</div><div><br></div><div><div>name = "test module"</div><div>core = 6.x</div><div><br>
</div></div></div></div></div></div><br clear="all">--<br>Regards,<br>Nitin Kumar Gupta<br><a href="http://publicmind.in/blog/">http://publicmind.in/blog/</a><br>