Hello,
I created a module that hooks to the forms system_site_information_settings. My objective is to store additional fields per domain; the module works ok with one domain however, when I submit the form the values are set equally for all domains. How can I store individual values for each domain? Below is the module I created:
/**
* @filesource
* mysiteinfo.module
*/
function mysiteinfo_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'system_site_information_settings') {
$form['mysiteinfo_extra_setting2'] = array(
'#type' => 'textfield',
'#title' => t('Facebook'),
'#default_value' => variable_get('mysiteinfo_extra_setting2'),
);
$form['mysiteinfo_extra_setting3'] = array(
'#type' => 'textfield',
'#title' => t('Twitter'),
'#default_value' => variable_get('mysiteinfo_extra_setting3'),
);
$form['mysiteinfo_extra_setting4'] = array(
'#type' => 'textfield',
'#title' => t('Google'),
'#default_value' => variable_get('mysiteinfo_extra_setting4'),
);
$form['mysiteinfo_extra_setting5'] = array(
'#type' => 'textfield',
'#title' => t('Pinterest'),
'#default_value' => variable_get('mysiteinfo_extra_setting5'),
);
$form['mysiteinfo_extra_setting6'] = array(
'#type' => 'textfield',
'#title' => t('RSS'),
'#default_value' => variable_get('mysiteinfo_extra_setting6'),
);
}
// extra submit form handle
$form['#submit'][] = 'mysiteinfo_form_submit';
}
// handle form submition
function mysiteinfo_form_submit($form, &$form_state){
$values = $form_state['values'];
if(!empty($values['mysiteinfo_extra_setting2'])){
variable_set('mysiteinfo_extra_setting2', $values['mysiteinfo_extra_setting2']);
}
if(!empty($values['mysiteinfo_extra_setting3'])){
variable_set('mysiteinfo_extra_setting3', $values['mysiteinfo_extra_setting3']);
}
if(!empty($values['mysiteinfo_extra_setting4'])){
variable_set('mysiteinfo_extra_setting3', $values['mysiteinfo_extra_setting4']);
}
if(!empty($values['mysiteinfo_extra_setting5'])){
variable_set('mysiteinfo_extra_setting3', $values['mysiteinfo_extra_setting5']);
}
if(!empty($values['mysiteinfo_extra_setting6'])){
variable_set('mysiteinfo_extra_setting3', $values['mysiteinfo_extra_setting6']);
}
}
Comments
Comment #1
agentrickardLook in domain.api.php for hook_domain_batch().
Comment #2
joebest commentedSince I'm quite new at this, what should be done once I'm there?
Comment #3
agentrickardAdd all your new variables to a mymodule_domain_batch() function, following the documentation.
See domain_conf_domain_batch() for lots of examples.
Comment #4
joebest commentedI really do not how to start. Would it it be much to ask for a step by step way of how to proceed as it was a newbie with zero experience?
Best regards,
Comment #5
agentrickardYes. It would. It's an API function similar to the hook_form_alter() you posted above. It is well-documented, and there are examples.
BTW, you can use system_settings_form() instead of a custom submit handler. See http://api.drupal.org/api/drupal/modules!system!system.module/function/s...
You should also use hook_form_system_site_information_settings_alter() instead of hook_form_alter() for performance (and readability). See http://api.drupal.org/api/drupal/modules!system!system.api.php/function/...
Comment #6
joebest commentedThanks for the insight.
Comment #7
mikeaskew4 commentedUsing hook_domain_batch() in a custom module, how would one go about making tokens from these custom fields?