I have a custom module that I have created to display 3 different images with a 'vote' beneath each image. The idea is to have the viewer vote on the one they like and it gets ranked against the other 2 images using votingAPI. What I am trying to do on callback is do the voting calculations (which I have), then replace the buttons with the voting percentage for each of the images. Wait 3 seconds and refresh the form with 3 more images.
What I am having difficulty with right now is just redrawing the form after submit, with the same 3 images and the percentage displaying instead of the button.
Here is the code I am using to define the block, block_view, and form. Any suggestions or help would be greatly appreciated.
function steal_or_burn_block_info() {
$blocks = array();
$blocks['steal_or_burn'] = array(
'info' => t('Steal or Burn Homepage Block'),
'cache' => DRUPAL_NO_CACHE,
);
return $blocks;
}
function steal_or_burn_block_view($delta = '') {
$block = array();
switch($delta) {
case 'steal_or_burn':
$block['subject'] = ("Favorite Image");
$block['content'] = drupal_get_form('steal_or_burn_form');
}
return $block;
}
function steal_or_burn_form($form, &$form_state) {
$has_cookie = get_cookie('stealorburn');
// Get the previous Steal or Burn NodeId's as an array
$prev_sob_nids = get_sob_cookie_nids(COOKIE_NAME);
// Load the NodeId's of the remaining Steal or Burn images in the database
$unviewed_nids = load_sob_node_ids('stealorburn');
// Find the difference between the previously viewed NodeId's against the full database
// return an array of only those that have not yet been viewed
if($prev_sob_nids) {
$stealorburn_raw = array_diff($unviewed_nids, $prev_sob_nids);
} else {
$stealorburn_raw = $unviewed_nids;
}
// Randomize the array of not-yet-viewed Product images
shuffle($stealorburn_raw);
// Select the next 3 images to display
$stealorburn = array_slice($stealorburn_raw, 0,3, TRUE);
$i = 1;
foreach($stealorburn as $value) {
$node = node_load($value);
$image = field_get_items('node', $node, 'field_brand_image');
$image_rendered = field_view_value('node', $node, 'field_brand_image', $image[0], array(
'type' => 'image',
'settings' => array(
'image_style' => 'thumbnail',
),
));
$brand = $node->title;
$item_name = field_get_items('node', $node, 'field_item_name');
$item_id = $node->nid;
$image_uri = $image_rendered['#item']['uri'];
$style = 'steal_burn_home_image';
$derivative_uri = image_style_path($style, $image_uri);
$new_image_url = file_create_url($derivative_uri);
switch ($i) {
case 1:
$submit_button = 'steal_burn_first';
break;
case 2:
$submit_button = 'steal_burn_second';
break;
case 3:
$submit_button = 'steal_burn_third';
break;
}
// Block output in HTML with div wrapper
$form['steal_or_burn_form'][]['image'] = array(
'#prefix' => "<div class='steal_burn_image_block_$i'>",
'#type' => 'markup',
'#markup' => "<img src='$new_image_url'>",
);
$form['steal_or_burn_form'][]['brand'] = array(
'#prefix' => '<div class="steal-or-burn-field-title">',
'#type' => 'markup',
'#markup' => $brand,
'#suffix' => '</div>',
);
$form['steal_or_burn_form'][]['item_name'] = array(
'#prefix' => '<div class="steal-or-burn-field-item-name">',
'#type' => 'markup',
'#markup' => $item_name[0]['value'],
'#suffix' => '</div>',
);
$form['steal_or_burn_form'][]['product_id'] = array(
'#type' => 'hidden',
'#value' => $item_id,
);
$form['steal_or_burn_form'][]['submit'] = array(
'#type' => 'submit',
'#id' => $submit_button,
'#name' => $node->nid,
'#value' => t('Vote'),
/*'#submit' => array('steal_or_burn_submission_callback'),*/
);
$i++;
} // end block image loop
return $form['steal_or_burn_form'];
}