I've now spent two days researching and attempting to get a custom submit function to run. I've run every search I can think of and nothing seems to work. I used form_alter to successfully add a text input to a form. It seems like adding a custom function should be pretty straightforward, but none of the examples I have seen seems to work. I have two questions.
1. What is the best way to see if a function is being called? I tried putting a drupal_set_message in the function and it doesn't get displayed, but I'm not sure setting a message inside of a submit function will work even if the function runs.
2. How on earth do I get the custom submit function to run?
This is what I have so far. The textfield is added, but the submit function doesn't seem to run at all.
function bookmarks_blocks_form_alter($form_id, &$form) {
switch ($form_id) {
case 'bookmarks_form':
$form['#submit']['bookmarks_blocks_form_alter_submit'] = current($form['#submit']);
$form['details']['weight'] = array(
'#type' => 'textfield',
'#title' => t('Weight'),
'#default_value' => '1',
'#size' => 3,
'#maxlength' => 3,
'#description' => null,
'#attributes' => null,
'#required' => true,
'#weight' => 0,
);
break;
}
}
function bookmarks_blocks_form_alter_submit($form_id, $form_values) {
drupal_set_message(t('Submit Function Executed!'));
}
Comments
might just be this
$form['#submit']['bookmarks_blocks_form_alter_submit'] = array('hook_submit'=>0);everything should be stored in an array.
where did you get that example from?
Are you aware of the Drupal API Docs?
You may have got confused because your attempt appears to be more like a Drupal 6 API version, but it changed from Drupal5 - which you tagged this post as.
The docs include a clear example of both styles
.dan.
if you are asking a question you think should be documented, please provide a link to the handbook where you think the answer should be found.
| http://www.coders.co.nz/ |
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Thanks for the replies. No
Thanks for the replies. No luck, though.
I started out with the code from the Drupal 5 section of the Drupal API Docs. When that didn't work I looked elsewhere. I'm not sure where the code I posted above came from. My current best guess is that the module I'm trying to extend (http://drupal.org/project/bookmarks) does not use the normal drupal submit which means my hook is not getting called. I'm not familiar enough with what the standard form submit code looks like to say for sure, though.
Also, can anyone tell me if the drupal_set_message will display if it is inside a custom submit function?
--Fett
Have you seen
Have you seen this?
http://symbiotix.net/articles/how-add-one-or-more-custom-submit-handlers...