我有2個提交按鈕,並且想要爲每個提交按鈕執行不同的操作。在這裏我想設置只能在form_alter()中完成的表單域。任何人都可以建議如何檢查form_alter()函數中的多個提交按鈕?在Drupal表單中處理多個提交按鈕API
我用
function myform_form_submit($formID, &$form_state) {
if($form_state['clicked_button']['#value'] == $form_state['values']['submit_one']) //if button 1 is clicked
$form_state['redirect'] = 'mypath/page_one'; //redirect to whatever page you want
else if($form_state['clicked_button']['#value'] == $form_state['values']['submit_two']) /if button 2 is clicked
$form_state['redirect'] = 'mypath/page_two';
}
但這不起作用
你的表單中有提交鉤子嗎? $ form ['#submit'] [] ='myform_form_submit'; ? – Kevin 2010-12-21 18:20:06
是的,但不是Drupal應該拿起提交功能,即使沒有上述掛鉤? – user550265 2010-12-22 15:02:43