I have a Drupal 7 multi-site installation with some shared modules. Some of these modules declares some forms. And here comes the problem: How to make these forms look different in two different sites? For example: In one site the whole form needs to be on a single page but in another site it needs to be divided in two steps, how can I solve this without change the module code?

I tought in some solutions:

  • Create a custom module for the site that needs the form to be in two steps.
  • Break in two steps using javascript and handle the navigation on the client site.
  • Create a configuration on the shared module (the problem here is that I'd have to create a specific configuration for every possible customization on the form).
  • Create a template for the form and handle this steps in specific site theme.
  • Change the module to, instead of creating a form using FAPI, creates a webform node that could be changed for the specific site when the module is installed.

What would be perfect for me is that is someway I could implement a form alter hook in the theme but it isn't possible, right?

What do you think? How you solve this problem?

2 Answers 2


Create three modules named site1.module, site2.module and site1site2.module respectively. Store changes (hook_form_alters) for site1's forms (including those of your custom module) in site1.module, sites2's forms in site2.module, and forms of both sites in site1site2.module.

The module names will of course need to be swapped for more meaningful alternatives.


You can always call hook_form_FORM_ID_form_alter (not sure about the exact hook name) in a custom module you create and change the form according to a URL that is probably different depending on the site that you are accessing:

function mymodule_form_myform_form_alter($form, &$form_state){
         case 'www.mywebsite1.com': $form['new_field'] = array('#type','textfield');
         case 'www.mywebsite2.com': $form['new_field'] = array('#type','textarea');
  • I didn't like your solution. My url changes depending on the environment (dev, test and production). I don't think it's a good idea to hardcode this kind of things on my module. Jan 11, 2012 at 18:43
  • It doesn't matter how you recognize your current site, I thought url might be good, you can set a cookie or check a database field or do as you wish. The answer is still valid, depending on your site you can do form changes with what I wrote. Of course the switch has to be modified accordingly.
    – reptilex
    Jan 13, 2012 at 9:34
  • Despite the hard-coded urls (which might be centralized somewhere and made available through vars), what do you expect? There must be some way to distinguish which site of the multisite environment is requesting the form and my first thought would also be the url.
    – Paul
    Jan 13, 2012 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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