You are here

function advpoll_promote_writein_form_submit in Advanced Poll 7

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

File

includes/advpoll.pages.inc, line 414

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) {
      $nodeChoices = $node->advpoll_choice[$node->language];
      $updatedChoices = array();
      foreach ($nodeChoices as $item) {
        $choice = strtolower(strip_tags($item['choice']));
        if (in_array($choice, $selected)) {
          $updatedChoices[] = array(
            'choice' => $item['choice'],
            'write_in' => 0,
            'choice_id' => $item['choice_id'],
          );
        }
        else {
          $updatedChoices[] = array(
            'choice' => $item['choice'],
            'write_in' => $item['write_in'],
            'choice_id' => $item['choice_id'],
          );
        }
      }
      $node->advpoll_choice[$node->language] = $updatedChoices;
      node_save($node);
    }
  }
}