You are here

function advpoll_process_writein in Advanced Poll 7.3

Same name and namespace in other branches
  1. 7 advpoll.module \advpoll_process_writein()
  2. 7.2 advpoll.module \advpoll_process_writein()

Processes write-in value.

Write in choice is added to node here. Note that before the write in value is passed off to be saved, it is sanitized and checked in the form submit This allows the submit function to provide appropriate messaging if the resulting sanitized value returns as empty.

Parameters

$nid: Node id of the poll.

$writein: The sanitized input of the write-in field.

$data: A data object of the relevant fields for the node. It is defined by the helper functions in advpoll_helper.inc.

Return value

Returns an array in the same format as a choice field: choice: The text of the choice choice_id: The unique ID of the choice write_in: Boolean indicating whether or not the chioce was provided by a write-in vote. In this case it is always TRUE.

2 calls to advpoll_process_writein()
advpoll_form_submit in ./advpoll.module
Submit handler for voting.
advpoll_ranking_submit in advpoll_ranking/advpoll_ranking.module
Submit handler for ranking polls.

File

./advpoll.module, line 894

Code

function advpoll_process_writein($nid, $writein, $data) {
  $node = node_load($nid);
  $id = dechex(time() * rand(5, 50));
  $writein_choice = array();
  if ($node) {
    $lang = entity_language('node', $node);
    $node_choices = $node->advpoll_choice[$lang];
    $writein_choice = array(
      'choice' => $writein,
      'write_in' => 1,
      'choice_id' => $id,
    );
    $node_choices[] = $writein_choice;
    $node->advpoll_choice[$lang] = $node_choices;
    node_save($node);
  }
  return $writein_choice;
}