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.
Comments
Comment #1
anders.fajerson commentedThe 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
Comment #2
ChrisKennedy commentedYeah 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.
Comment #3
anders.fajerson commentedNot 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.
Comment #4
ChrisKennedy commentedI think you can create $_POST['choices'] with your data just like in any other array.
http://drupal.org/cvs?commit=90111
Comment #5
(not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.