You are here

function simple_adsense_settings in Simple AdSense 7

Form_simple_adsense.

1 string reference to 'simple_adsense_settings'
simple_adsense_menu in ./simple_adsense.module
Implements hook_menu().

File

./simple_adsense.admin.inc, line 11
Configuration form.

Code

function simple_adsense_settings($form, &$form_state) {
  $form['#tree'] = TRUE;
  $form['description'] = array(
    '#type' => 'item',
    '#title' => t('Settings for simple adsense'),
  );
  $form['client'] = array(
    '#type' => 'textfield',
    '#title' => t('Client'),
    '#required' => TRUE,
    '#description' => 'Google AdSense Publisher Id. eg: pub-9513614146655499',
    '#default_value' => variable_get("simple_adsense_client", 'pub-9513614146655499'),
  );
  $slots = variable_get("simple_adsense_slots", NULL);
  if (empty($form_state['num_slots'])) {
    if (isset($slots)) {
      $form_state['num_slots'] = count($slots);
    }
    else {
      $form_state['num_slots'] = 1;
    }
  }
  for ($i = 1; $i <= $form_state['num_slots']; $i++) {
    $form['slot'][$i] = array(
      '#type' => 'textfield',
      '#title' => t("AD Unit @num's ID", array(
        '@num' => $i,
      )),
      '#required' => TRUE,
      '#description' => "AD Unit ID, eg: 5725906500",
      '#default_value' => isset($slots[$i]) ? $slots[$i] : NULL,
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',
  );
  $form['add_slot'] = array(
    '#type' => 'submit',
    '#value' => t('Add another AD Unit ID'),
    '#submit' => array(
      'simple_adsense_settings_add_slot',
    ),
  );
  if ($form_state['num_slots'] > 1) {
    $form['remove_slot'] = array(
      '#type' => 'submit',
      '#value' => t('Remove Last AD Unit ID'),
      '#submit' => array(
        'simple_adsense_settings_remove_slot',
      ),
      '#limit_validation_errors' => array(),
    );
  }
  return $form;
}