Multiple Forms, single form handler
Howdy, I'm working with a module called 'invite' (not sure if its drupal core or not) and i've added some hooks to allow it to work as a block as well as a regular module. The block is working fine and I have managed to build a form using the standard Drupal forms API successfully. The form submits to my validate function correctly and validates the submitted details as it should. Now, in order to save time and re-use existing code, I would like the form in my block to use the same methods and routines for saving information that the main form uses when you view it directly and fill out that form and submit that (http://drupal.local/invite/). The main form has two fields that are submitted (email address, required - description, not required) and my Block form has a single field (email address). The form built in my block is named 'invites_block_form' and the main form is named 'invite_form' I've attempted to use hook_forms() to achieve this behavior as outlined in the 'Pro Drupal Development' book but cant quite get my head around how to achieve it. If anyone could provide some insight into how to achieve this I would be greatful. Cheers, James McLean
You're making it too complicated - you can set the form #base, to get it to use an alternate 'base' for the validate and submit functions. see, for example: http://drupal.org/node/73973 and also: http://api.drupal.org/api/5/file/developer/topics/forms_api_reference.html#b... and please read these API docs well. -Peter On 6/19/07, James McLean <james.mclean@gmail.com> wrote:
Howdy,
I'm working with a module called 'invite' (not sure if its drupal core or not) and i've added some hooks to allow it to work as a block as well as a regular module. The block is working fine and I have managed to build a form using the standard Drupal forms API successfully.
The form submits to my validate function correctly and validates the submitted details as it should.
Now, in order to save time and re-use existing code, I would like the form in my block to use the same methods and routines for saving information that the main form uses when you view it directly and fill out that form and submit that (http://drupal.local/invite/). The main form has two fields that are submitted (email address, required - description, not required) and my Block form has a single field (email address).
The form built in my block is named 'invites_block_form' and the main form is named 'invite_form'
I've attempted to use hook_forms() to achieve this behavior as outlined in the 'Pro Drupal Development' book but cant quite get my head around how to achieve it.
If anyone could provide some insight into how to achieve this I would be greatful.
Cheers,
James McLean
On 6/20/07, Peter Wolanin <pwolanin@gmail.com> wrote:
You're making it too complicated - you can set the form #base, to get it to use an alternate 'base' for the validate and submit functions.
see, for example: http://drupal.org/node/73973
and also: http://api.drupal.org/api/5/file/developer/topics/forms_api_reference.html#b... and please read these API docs well.
Thanks a lot for this suggestion, the #base option was exactly what I needed and works as expected. Thanks! Cheers, James McLean
The basic way I do this: function invites_block_form_submit($formid,$form_values) { invites_save_invite($form_values); } function invites_form_submit($formid,$form_values) { invites_save_invite($form_values); } function invites_save_invite($fields) { // common stuff here } It doesn't have to be more complicated than that. On Jun 19, 2007, at 5:11 PM, James McLean wrote:
Howdy,
I'm working with a module called 'invite' (not sure if its drupal core or not) and i've added some hooks to allow it to work as a block as well as a regular module. The block is working fine and I have managed to build a form using the standard Drupal forms API successfully.
The form submits to my validate function correctly and validates the submitted details as it should.
Now, in order to save time and re-use existing code, I would like the form in my block to use the same methods and routines for saving information that the main form uses when you view it directly and fill out that form and submit that (http://drupal.local/invite/). The main form has two fields that are submitted (email address, required - description, not required) and my Block form has a single field (email address).
The form built in my block is named 'invites_block_form' and the main form is named 'invite_form'
I've attempted to use hook_forms() to achieve this behavior as outlined in the 'Pro Drupal Development' book but cant quite get my head around how to achieve it.
If anyone could provide some insight into how to achieve this I would be greatful.
Cheers,
James McLean
participants (4)
-
David Metzler -
James McLean -
Khalid Baheyeldin -
Peter Wolanin