Ik am doing a very simple form where I add a button which should do some functionality, but it's not working. Altough the button is visible on the page and when I click it the page is refreshed. Can anyone see what's wrong with this code ?
function donation_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'wedding_article_node_form') {
$form['add_donation'] = array(
'#type' => 'button',
'#submit' => array('donation_add_donation'),
'#value' => t('Add donation'),
);
}
}
function donation_add_donation(&$form, &$form_state) {
dpm('test');
dpm($form);
}
You need a submit
type element if you want to run a submit handler. From the documentation:
When the button is pressed, the form will be submitted to Drupal, where it is validated and rebuilt. The submit handler is not invoked.
(emphasis mine)