Mercurial > defr > drupal > core
comparison modules/poll/poll.module @ 19:3edae6ecd6c6 6.9
Drupal 6.9
author | Franck Deroche <franck@defr.org> |
---|---|
date | Thu, 15 Jan 2009 10:15:56 +0100 |
parents | acef7ccb09b5 |
children |
comparison
equal
deleted
inserted
replaced
18:f5131a9cd9e5 | 19:3edae6ecd6c6 |
---|---|
1 <?php | 1 <?php |
2 // $Id: poll.module,v 1.263.2.2 2008/08/13 23:59:13 drumm Exp $ | 2 // $Id: poll.module,v 1.263.2.3 2008/12/18 15:46:20 dries Exp $ |
3 | 3 |
4 /** | 4 /** |
5 * @file | 5 * @file |
6 * Enables your site to capture votes on different topics in the form of multiple | 6 * Enables your site to capture votes on different topics in the form of multiple |
7 * choice questions. | 7 * choice questions. |
286 // Set the form to rebuild and run submit handlers. | 286 // Set the form to rebuild and run submit handlers. |
287 node_form_submit_build_node($form, $form_state); | 287 node_form_submit_build_node($form, $form_state); |
288 | 288 |
289 // Make the changes we want to the form state. | 289 // Make the changes we want to the form state. |
290 if ($form_state['values']['poll_more']) { | 290 if ($form_state['values']['poll_more']) { |
291 $form_state['choice_count'] = count($form_state['values']['choice']) + 5; | 291 $n = $_GET['q'] == 'poll/js' ? 1 : 5; |
292 $form_state['choice_count'] = count($form_state['values']['choice']) + $n; | |
292 } | 293 } |
293 } | 294 } |
294 | 295 |
295 function _poll_choice_form($delta, $value = '', $votes = 0) { | 296 function _poll_choice_form($delta, $value = '', $votes = 0) { |
296 $admin = user_access('administer nodes'); | 297 $admin = user_access('administer nodes'); |
324 | 325 |
325 /** | 326 /** |
326 * Menu callback for AHAH additions. | 327 * Menu callback for AHAH additions. |
327 */ | 328 */ |
328 function poll_choice_js() { | 329 function poll_choice_js() { |
329 $delta = count($_POST['choice']); | 330 include_once 'modules/node/node.pages.inc'; |
330 | 331 $form_state = array('storage' => NULL, 'submitted' => FALSE); |
331 // Build our new form element. | |
332 $form_element = _poll_choice_form($delta); | |
333 drupal_alter('form', $form_element, array(), 'poll_choice_js'); | |
334 | |
335 // Build the new form. | |
336 $form_state = array('submitted' => FALSE); | |
337 $form_build_id = $_POST['form_build_id']; | 332 $form_build_id = $_POST['form_build_id']; |
338 // Add the new element to the stored form. Without adding the element to the | 333 // Get the form from the cache. |
339 // form, Drupal is not aware of this new elements existence and will not | 334 $form = form_get_cache($form_build_id, $form_state); |
340 // process it. We retreive the cached form, add the element, and resave. | 335 $args = $form['#parameters']; |
341 if (!$form = form_get_cache($form_build_id, $form_state)) { | 336 $form_id = array_shift($args); |
342 exit(); | 337 // We will run some of the submit handlers so we need to disable redirecting. |
343 } | 338 $form['#redirect'] = FALSE; |
344 $form['choice_wrapper']['choice'][$delta] = $form_element; | 339 // We need to process the form, prepare for that by setting a few internals |
345 form_set_cache($form_build_id, $form, $form_state); | 340 // variables. |
346 $form += array( | 341 $form['#post'] = $_POST; |
347 '#post' => $_POST, | 342 $form['#programmed'] = FALSE; |
348 '#programmed' => FALSE, | 343 $form_state['post'] = $_POST; |
349 ); | 344 // Build, validate and if possible, submit the form. |
350 | 345 drupal_process_form($form_id, $form, $form_state); |
351 // Rebuild the form. | 346 // This call recreates the form relying solely on the form_state that the |
352 $form = form_builder('poll_node_form', $form, $form_state); | 347 // drupal_process_form set up. |
353 | 348 $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id); |
354 // Render the new output. | 349 // Render the new output. |
355 $choice_form = $form['choice_wrapper']['choice']; | 350 $choice_form = $form['choice_wrapper']['choice']; |
356 unset($choice_form['#prefix'], $choice_form['#suffix']); // Prevent duplicate wrappers. | 351 unset($choice_form['#prefix'], $choice_form['#suffix']); // Prevent duplicate wrappers. |
357 $choice_form[$delta]['#attributes']['class'] = empty($choice_form[$delta]['#attributes']['class']) ? 'ahah-new-content' : $choice_form[$delta]['#attributes']['class'] .' ahah-new-content'; | |
358 $choice_form[$delta]['chvotes']['#value'] = 0; | |
359 $output = theme('status_messages') . drupal_render($choice_form); | 352 $output = theme('status_messages') . drupal_render($choice_form); |
360 | 353 |
361 drupal_json(array('status' => TRUE, 'data' => $output)); | 354 drupal_json(array('status' => TRUE, 'data' => $output)); |
362 } | 355 } |
363 | 356 |