You are here

function _poll_choice_form in Drupal 7

Same name and namespace in other branches
  1. 6 modules/poll/poll.module \_poll_choice_form()
1 call to _poll_choice_form()
poll_form in modules/poll/poll.module
Implements hook_form().

File

modules/poll/poll.module, line 381
Enables your site to capture votes on different topics in the form of multiple choice questions.

Code

function _poll_choice_form($key, $chid = NULL, $value = '', $votes = 0, $weight = 0, $size = 10) {
  $form = array(
    '#tree' => TRUE,
    '#weight' => $weight,
  );

  // We'll manually set the #parents property of these fields so that
  // their values appear in the $form_state['values']['choice'] array.
  $form['chid'] = array(
    '#type' => 'value',
    '#value' => $chid,
    '#parents' => array(
      'choice',
      $key,
      'chid',
    ),
  );
  $form['chtext'] = array(
    '#type' => 'textfield',
    '#title' => $value !== '' ? t('Choice label') : t('New choice label'),
    '#title_display' => 'invisible',
    '#default_value' => $value,
    '#parents' => array(
      'choice',
      $key,
      'chtext',
    ),
  );
  $form['chvotes'] = array(
    '#type' => 'textfield',
    '#title' => $value !== '' ? t('Vote count for choice @label', array(
      '@label' => $value,
    )) : t('Vote count for new choice'),
    '#title_display' => 'invisible',
    '#default_value' => $votes,
    '#size' => 5,
    '#maxlength' => 7,
    '#parents' => array(
      'choice',
      $key,
      'chvotes',
    ),
    '#access' => user_access('administer nodes'),
    '#element_validate' => array(
      'element_validate_integer',
    ),
  );
  $form['weight'] = array(
    '#type' => 'weight',
    '#title' => $value !== '' ? t('Weight for choice @label', array(
      '@label' => $value,
    )) : t('Weight for new choice'),
    '#title_display' => 'invisible',
    '#default_value' => $weight,
    '#delta' => $size,
    '#parents' => array(
      'choice',
      $key,
      'weight',
    ),
  );
  return $form;
}