You are here

function advpoll_promote_writein_form_submit in Advanced Poll 7.3

Same name and namespace in other branches
  1. 7 includes/advpoll.pages.inc \advpoll_promote_writein_form_submit()
  2. 7.2 includes/advpoll.pages.inc \advpoll_promote_writein_form_submit()

Submit callback for advpoll_promote_writein_form.

File

includes/advpoll.pages.inc, line 525
Advanced Poll Pages Include.

Code

function advpoll_promote_writein_form_submit($form, &$form_state) {
  $selected = array();
  $nid = $form_state['build_info']['args'][0]->nid;
  $options = $form['promote_writein']['choices']['#options'];
  foreach ($options as $option) {
    if ($form['promote_writein']['choices'][$option]['#checked']) {
      $selected[] = strtolower(strip_tags($option));
    }
  }
  if ($selected) {
    $node = node_load($nid);
    if ($node) {
      $lang = $node->language;
      if (!isset($node->advpoll_choice[$lang])) {
        $lang = LANGUAGE_NONE;
      }
      $node_choices = $node->advpoll_choice[$lang];
      $updated_choices = array();
      foreach ($node_choices as $item) {
        $choice = strtolower(strip_tags($item['choice']));
        if (in_array($choice, $selected)) {
          $updated_choices[] = array(
            'choice' => $item['choice'],
            'write_in' => 0,
            'choice_id' => $item['choice_id'],
          );
        }
        else {
          $updated_choices[] = array(
            'choice' => $item['choice'],
            'write_in' => $item['write_in'],
            'choice_id' => $item['choice_id'],
          );
        }
      }
      $node->advpoll_choice[$lang] = $updated_choices;
      node_save($node);
    }
  }
}