Don't know if this is a bug or a feature, but I had to fix it to get programmatic creation of advpoll_binary nodes to work. Currently, _advpoll_insert_choices($node) will only work if it is called as the result of a form submission as the foreach loop iterates over the $_POST variable like so:

foreach ($_POST['choice'] as $choice) {
    if ($choice['label'] != '') {
      db_query("INSERT INTO {advpoll_choices} (nid, label, vote_offset) VALUES (%d, '%s', %d)", $node->nid, $choice['label'], $i++);
    }
}

Changing the loop to

foreach ($node->choice as $choice) {

does the same thing, but allows creation of nodes via a programmatic call to node_save as opposed to through a form submit.

CommentFileSizeAuthor
#2 advpoll_insert_choices.patch747 bytesChrisKennedy

Comments

anders.fajerson’s picture

Version: 5.x-1.0-beta4 » 5.x-1.x-dev
Priority: Normal » Critical

The use of $_POST is part of our dynamic choice edit form, right? It should be documented in the code in that case.

I wonder if this affects the use of e.g drupal_execute() which could be used to programatically create polls, related to http://drupal.org/node/149946

ChrisKennedy’s picture

Status: Active » Needs review
StatusFileSize
new747 bytes

Yeah for D5 we need to use _POST. Here's a documentation patch.

You should still be able to use drupal_execute though, you'll just want to send the choice data using _POST.

anders.fajerson’s picture

Status: Needs review » Reviewed & tested by the community

Not sure how you would send the data programatically with _POST, but that is a support request. I was thinking if there was a way of making this function a bit smarter, like checking both _POST and node->choice. Anyway, the documentation should get in.

ChrisKennedy’s picture

Status: Reviewed & tested by the community » Fixed

I think you can create $_POST['choices'] with your data just like in any other array.

http://drupal.org/cvs?commit=90111

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.