You are here

function sendinblue_signup_subscribe_form in SendinBlue 7

Same name and namespace in other branches
  1. 7.2 sendinblue.module \sendinblue_signup_subscribe_form()

Returns a subscription form for sendinblue lists.

1 string reference to 'sendinblue_signup_subscribe_form'
sendinblue_forms in ./sendinblue.module
Implements hook_forms().

File

./sendinblue.module, line 259
The entry point of Sendinblue module.

Code

function sendinblue_signup_subscribe_form($form, &$form_state, $signup, $type) {
  $form['#attributes'] = array(
    'class' => array(
      'sendinblue-signup-subscribe-form',
    ),
  );
  $form['description'] = array(
    '#markup' => check_plain($signup->settings['description']),
  );
  $form['fields'] = array(
    '#prefix' => '<div id="sendinblue-newsletter-' . check_plain($signup->settings['subscription']['settings']['list']) . '-mergefields" class="sendinblue-newsletter-mergefields">',
    '#suffix' => '</div>',
    '#tree' => TRUE,
  );
  if (isset($signup->settings['fields']['mergefields'])) {
    $merge_fields = $signup->settings['fields']['mergefields'];
    $attributes = variable_get(SendinblueManager::ATTRIBUTE_LISTS, array());
    if (is_array($merge_fields)) {
      foreach ($merge_fields as $key => $value) {
        if ($key == 'EMAIL') {
          $form['fields'][$key] = array(
            '#type' => 'textfield',
            '#title' => check_plain($value['label']),
            '#attributes' => array(
              'style' => 'width:100%;box-sizing:border-box;',
            ),
            '#required' => TRUE,
          );
        }
        else {
          if (isset($value['check'])) {
            foreach ($attributes as $attribute) {
              if ($attribute['name'] == $key) {
                $type = $attribute['type'];
                if ($type == 'category') {
                  $enumerations = $attribute['enumeration'];
                }
                break;
              }
            }
            if ($type != 'category') {
              $form['fields'][$key] = array(
                '#type' => 'textfield',
                '#title' => check_plain($value['label']),
                '#attributes' => array(
                  'style' => 'width:100%;box-sizing:border-box;',
                ),
                '#required' => isset($value['required']) ? TRUE : FALSE,
              );
            }
            else {
              $options = array();
              foreach ($enumerations as $enumeration) {
                $options[$enumeration['value']] = $enumeration['label'];
              }
              $form['fields'][$key] = array(
                '#type' => 'select',
                '#title' => check_plain($value['label']),
                '#options' => $options,
                '#attributes' => array(
                  'style' => 'width:100%;box-sizing:border-box;',
                ),
                '#required' => isset($value['required']) ? TRUE : FALSE,
              );
            }
          }
        }
      }
    }
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#weight' => 10,
    '#value' => check_plain($signup->settings['fields']['submit_button']),
  );
  return $form;
}