function advpoll_ranking_choice_form in Advanced Poll 7
Same name and namespace in other branches
- 7.3 advpoll_ranking/advpoll_ranking.module \advpoll_ranking_choice_form()
- 7.2 advpoll_ranking/advpoll_ranking.module \advpoll_ranking_choice_form()
2 string references to 'advpoll_ranking_choice_form'
- advpoll_ranking_cancel_submit in advpoll_ranking/
advpoll_ranking.module - advpoll_ranking_node_view in advpoll_ranking/
advpoll_ranking.module
File
- advpoll_ranking/
advpoll_ranking.module, line 241
Code
function advpoll_ranking_choice_form($form, &$form_state, $values) {
$data = advpoll_get_data($values);
$count = count($data->choices);
// values are necessary to render select list. This means that the user can't allow more than
// 10 rankable items.
$ranking = array(
'--',
'1st',
'2nd',
'3rd',
'4th',
'5th',
'6th',
'7th',
'8th',
'9th',
'10th',
);
$options = array();
$form['#id'] = 'advpoll-ranking-form-' . $values->nid;
$form['choice'] = array(
'#tree' => TRUE,
);
// need some way to get the unique NID value for javascript. This assists with
// issues inwhich more than one ranking poll is displaying on a page.
$form['identity-markup'] = array(
'#type' => 'item',
'#markup' => '<div class="advpoll-identity" nid="' . $values->nid . '"></div>',
);
for ($i = 0; $i < $count; $i++) {
if (!$data->choices[$i]['write_in']) {
$form['choice'][$i] = array(
'#type' => 'select',
'#title' => strip_tags($data->choices[$i]['choice']),
'#options' => $ranking,
);
}
}
if ($data->write_in) {
$form['write_in'] = array(
'#type' => 'textfield',
'#title' => t('Write-in'),
'#size' => '30',
);
// if JS is not used to render the draggable table markup, this value will not
// change - therefore we have an option about how to handle write-in values
// upon submit.
$form['write_in_weight'] = array(
'#type' => 'hidden',
'#default_value' => 'no-js',
);
}
$form['submit'] = array(
'#type' => 'submit',
'#ajax' => array(
'callback' => 'advpoll_ranking_submit',
'wrapper' => 'advpoll-ranking-form-' . $values->nid,
'name' => 'submit1',
),
'#value' => t('Vote'),
);
// Render draggable table with enough rows to accomodate possible choices.
// The table is ignored for submission values and is only for markup.
$rows = '';
for ($i = 0; $i < $data->max_choices; $i++) {
$rows .= '<tr class="draggable"><td valign="top" class="advpoll-weight item-' . $i . '"></td></tr>';
}
$form['advpoll-table'] = array(
'#type' => 'item',
'#prefix' => '<div class="advpoll-vote-region">',
'#suffix' => '</div>',
'#markup' => '<table id="advpolltable"><thead><tr><th>' . t('Your Vote') . '</th></tr><tbody>' . $rows . '</tbody></table>',
);
drupal_add_tabledrag('advpolltable', 'match', 'sibling', 'advpoll-weight');
return $form;
}