function webform_civicrm_configure_form in Webform CiviCRM Integration 6
Same name and namespace in other branches
- 6.2 webform_civicrm.module \webform_civicrm_configure_form()
- 7 webform_civicrm_forms.inc \webform_civicrm_configure_form()
- 7.2 webform_civicrm.module \webform_civicrm_configure_form()
Form to configure CiviCRM options for a Webform
1 string reference to 'webform_civicrm_configure_form'
- webform_civicrm_menu in ./
webform_civicrm.module - Implementation of hook_menu().
File
- ./
webform_civicrm_forms.inc, line 13
Code
function webform_civicrm_configure_form(&$form_state, $node) {
drupal_add_js(drupal_get_path('module', 'webform_civicrm') . '/webform_civicrm_forms.js', 'module', 'header');
drupal_add_css(drupal_get_path('module', 'webform_civicrm') . '/webform_civicrm_style.css');
civicrm_initialize();
$fields = webform_civicrm_get_fields();
if (empty($node->webform_civicrm)) {
$settings = array(
'prefix_known' => '',
'prefix_unknown' => '',
'message' => '',
'activity_type_id' => 0,
'activity_subject' => '',
);
}
else {
$settings = $node->webform_civicrm;
}
$enabled = webform_civicrm_enabled_fields($node);
$tokens = '<strong>' . t('Tokens Available:') . '</strong> [' . implode('], [', webform_civicrm_get_fields('tokens')) . '].';
$acts = webform_civicrm_get_options('activity_type', 'arr', t('- no activity -'));
$readme_link = array(
'!link' => 'href="/admin/help/webform_civicrm" target="_blank" class="popup-webform-civicrm-help"',
);
$form = array(
'#prefix' => t('Use the options below to configure CiviCRM processing for this form.'),
);
// AJAXify help text
if (module_exists('popups')) {
popups_add_popups(array(
".popup-webform-civicrm-help" => array(
'width' => '90%',
),
));
}
$form['nid'] = array(
'#type' => 'checkbox',
'#title' => t('Enable CiviCRM Processing'),
'#default_value' => !empty($settings['nid']),
'#return_value' => $node->nid,
'#description' => '<ul><li>' . t('CiviCRM contacts will be created or updated when users submit this webform.') . '</li><li>' . t('Logged-in users will have their contact info already filled-in for them.') . '</li><li>' . t('The form will also be auto-filled for anonymous users if you send them this link using CiviMail:') . '<br />' . url('node/' . $node->nid, array(
'query' => 'cid={contact.contact_id}&{contact.checksum}',
)) . '</li><li>' . t('<a !link>Read the instructions</a> for more info.', $readme_link) . '</li></ul>',
);
$form['prefix'] = array(
'#type' => 'fieldset',
'#title' => t('Introduction Text'),
'#description' => t('This text will appear at the top of the form. You may configure separate messages for known contacts (logged in users, or users following a hashed link from civimail) and unknown (anonymous) users.'),
);
$form['prefix']['prefix_known'] = array(
'#type' => 'textarea',
'#title' => t('Introduction text for known contacts'),
'#default_value' => $settings['prefix_known'],
'#description' => $tokens,
);
$form['prefix']['prefix_unknown'] = array(
'#type' => 'textarea',
'#title' => t('Introduction text for unknown contacts'),
'#default_value' => $settings['prefix_unknown'],
'#description' => t('No tokens available for unknown contacts.'),
);
$form['st_message'] = array(
'#type' => 'fieldset',
'#title' => t('User Message'),
'#description' => t("Useful if you don't want people messing up your database because they aren't the person you think they are (i.e. they are logged in as, or following a hashed link for, someone else)."),
);
$form['st_message']['toggle_message'] = array(
'#type' => 'checkbox',
'#title' => t('Display message to known contacts?'),
'#default_value' => !empty($settings['message']),
);
$form['st_message']['message'] = array(
'#type' => 'textfield',
'#title' => t('Message text (displayed as a Drupal status message)'),
'#default_value' => $settings['message'],
'#size' => 100,
'#maxlength' => 255,
'#description' => t('Enclose your "not you" link text in curly brackets {like this}.') . '<p>' . $tokens . '</p>',
);
if (empty($settings['message'])) {
$form['st_message']['message']['#default_value'] = t("You are viewing this form as [display name]. Please {click here if that's not you}.");
}
$form['act'] = array(
'#type' => 'fieldset',
'#title' => t('Create Activity'),
'#description' => t('Automatically create an activity for contacts when this form is submitted?'),
);
$form['act']['activity_type_id'] = array(
'#type' => 'select',
'#title' => t('Activity Type'),
'#options' => $acts,
'#default_value' => $settings['activity_type_id'],
);
$form['act']['activity_subject'] = array(
'#type' => 'textfield',
'#title' => t('Activity Subject'),
'#maxlength' => 255,
'#default_value' => $settings['activity_subject'],
);
$form['fields'] = array(
'#type' => 'fieldset',
'#title' => t('Enable Fields'),
'#description' => '<p class="web-civi-p">' . t('Webform components will be created for you automatically when you check these boxes. You may then configure, arrange, or delete them using the standard Webform interface.') . '</p>',
'#attributes' => array(
'class' => 'web-civi-container',
),
);
$form['fields']['box'] = array(
'#prefix' => '<div class="scrollme">',
'#suffix' => '</div>',
);
// Three columns for neatness
$form['fields']['box']['contact'] = array(
'#prefix' => '<div class="web-civi-3-col"><h4>' . t('Contact Fields') . '</h4><div class="web-civi-description">' . t('First and last name fields are <em>required</em> by CiviCRM in order to create new contacts.') . '</div>',
'#suffix' => '</div>',
);
$form['fields']['box']['groups'] = array(
'#prefix' => '<div class="web-civi-3-col"><h4>' . t('Groups and Tags') . '</h4><div class="web-civi-description">' . t('These fields will add contacts who submit this form to groups and tags of your choosing. Configuration is done by editing the webform component.') . '</div>',
'#suffix' => '</div>',
);
$form['fields']['box']['custom'] = array(
'#prefix' => '<div class="web-civi-3-col"><h4>' . t('Custom Fields') . '</h4><div class="web-civi-description">' . t('Correct handling of custom fields requires proper permission configuration.') . ' ' . t('<a !link>Read the instructions</a> for more info.', $readme_link) . '</div>',
'#suffix' => '</div>',
);
// CiviCRM fields are enabled through these checkboxes
$c = 'contact';
$sets = array(
'civicrm_first_name' => 'Contact',
'civicrm_street_address' => 'Address',
'civicrm_phone' => 'Phone',
'civicrm_groups' => 'Groups',
'civicrm_tags' => 'Tags',
);
foreach ($fields as $id => $field) {
$f = array(
'#type' => 'checkbox',
'#title' => $field['name'],
'#default_value' => $enabled[$id],
'#disabled' => !empty($enabled[$id]),
'#description' => $field['extra']['description'],
);
if ($id == 'civicrm_groups') {
$c = 'groups';
}
if (!strpos($id, 'custom')) {
// Suggested minimum enabled fields
if (empty($settings['nid']) && !empty($field['mandatory'])) {
$f['#default_value'] = TRUE;
}
// Create fieldsets
if (!empty($sets[$id])) {
$set = $sets[$id];
$form['fields']['box'][$c][$set] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#title' => $set,
);
}
}
else {
$c = 'custom';
if (strip_tags($field['custom_group']) != $set) {
$set = strip_tags($field['custom_group']);
$form['fields']['box'][$c][$set] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#title' => $set,
);
}
}
$form['fields']['box'][$c][$set][$id] = $f;
}
if ($c != 'custom') {
$form['fields']['box']['custom']['#prefix'] .= '<p>' . t('You have no custom fields enabled in CiviCRM.') . '</p>';
}
$form['options'] = array(
'#type' => 'fieldset',
'#title' => t('Additional Options'),
);
$form['options']['confirm_subscription'] = array(
'#prefix' => '<div class="web-civi-3-col">',
'#suffix' => '</div>',
'#type' => 'checkbox',
'#title' => t('Confirm Subscriptions'),
'#default_value' => !empty($settings['confirm_subscription']),
'#description' => t('Recommended. Send a confirmation email before adding contacts to publicly subscribable mailing list groups.') . '<br />' . t('Your public mailing lists:') . ' <em>' . implode(', ', webform_civicrm_get_options('mailing_lists', 'arr')) . '</em>',
);
$form['options']['block_unknown_users'] = array(
'#prefix' => '<div class="web-civi-3-col">',
'#suffix' => '</div>',
'#type' => 'checkbox',
'#title' => t('Block unknown users'),
'#default_value' => !empty($settings['block_unknown_users']),
'#description' => t('Only allow users to see this form if they are logged in or following a personalized link from CiviMail.'),
);
// Set a few defaults
if (empty($settings['nid'])) {
$form['act']['activity_subject']['#default_value'] = $node->title;
$form['options']['confirm_subscription']['#default_value'] = TRUE;
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save Settings'),
);
return $form;
}