2

I created a module that just uses the hook_form_alter to add additional fields to an existing form. The problem now is when I enter in the information and submit none of the information inputed in the additional fields get saved when I go back to the form.

1
  • What version of Drupal are you using? – sheena_d May 2 '12 at 5:28
3

Other modules aren't generally programmed to be aware of your custom additions and don't know where/how you want to save the data. If you add fields via hook_form_alter() then you should also add your own submit and possibly validation handlers to the form similarly to this:

$form['#validate'][] = 'mymodule_someform_custom_validation';
$form['#submit'][] = 'mymodule_someform_custom_submission';

In the validation handler you can then validate your custom field data (if needed) and in the submit function you should save it. Small amounts of information can be stored in a variable, but if there's bigger amounts of data from different users you'll probably want to create a custom database table where to store all the information in.

3
  • I think its depend of form, some forms don't need custom submit function and will handled by drupal. in this case we should override exists submit function of this form because it certainly has one... – Mohammad Ali Akbari May 2 '12 at 8:01
  • I'm adding to the Domain Conf Form. I can't find the hook_submission API. Note: This is on Drupal 7 – meijiOrO May 2 '12 at 15:15
  • @meijiOrO mymodule_someform_custom_validation and mymodule_someform_custom_submission would be the names of your custom form validation and submit handlers (functions) respectively (they are not hooks). – Madis May 2 '12 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.