Ajax Validation: Illegal Choice has been made

arcane - November 16, 2008 - 04:06
Project:Validation API
Version:6.x-1.0-rc4
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

Got an error message "An illegal choice has been detected. Please contact the site administrator." when submitting a form.
The actual error encountered was from the book Pro Drupal Development page 46 - if you have the book. The example defines a new Action called Beep Multiple times. When you go to configure the action, thats when you get the error. The error stops happening if I disable the module.

An explanation of this error appears at http://proofgroup.com/blog/2008/jul/debugging_mysterious_illegal_choice_...

#1

arcane - November 16, 2008 - 04:07

The actual code from the example is:

<?php
// $Id$

/**
* @file
* Provide a simulated beep.
*/

function beep_beep() {
  watchdog('beep','Beep!');
}

/**
* Implementation of hook_action_info().
*/
function beep_action_info() {
    $info['beep_beep_action'] = array(
        'type' => 'system',
        'description' => t('Beep Annoyingly'),
        'configurable' => FALSE,
        'hooks' => array(
            'any' => TRUE,
            'nodeapi' => array('view', 'insert', 'update', 'delete'),
            'comment' => array('view','insert', 'update', 'delete'),
            'user' => array('view', 'insert', 'update', 'delete', 'login'),
            'taxonomy' => array('insert', 'update', 'delete'),
        ),        
    );
    $info['beep_nultiple_beep_action'] = array(
        'type' => 'system',
        'description' => t('Beep multiple times'),
        'configurable' => TRUE,
        'hooks' => array(
            'any' => TRUE,
        ),        
    );   
   
    return $info;
}
   
/**
* Simulate a beep.  A drupal action
*/
function beep_beep_action() {
  beep_beep();
}

/**
* Form for configurable Drupal action to beep multiple times/
*/
function beep_multiple_beep_action_form($context) {
  $form['beeps'] = array(
    '#type' => 'textfield',
    '#title' => t('Number of beeps'),
    '#description' => t('Enter the number of times to beep when this action executes'),
    '#default_value' => isset($context['beeps']) ? $context['beeps'] : '1',
    '#required' => TRUE,
  );
  return $form;
}

function beep_multiple_beep_action_validate($form,$form_state) {
  $beeps = $form_state['values']['beeps'];
  if (!is_numeric($beeps)) {
    form_set_error('beeps', t('Please enter a numeric value.'));
  }
  else if ((int) $beeps > 10) {
    form_set_error('beeps', t('That would be annoying. Please choose fewer than 10 beeps.'));
  }
}

function beep_multiple_beep_action_submit($form, $form_state) {
  return array(
    'beeps' => (int) $form_state['values']['beeps']
  );
}

/**
* Configurable action. Beeps a specified number of times.
*/
function beep_multipl_beep_action($object, $context){
    for ($i=1; $i <$context['beeps']; $i++) {
      beep_beep(); 
    }
}

#2

TapocoL - December 2, 2008 - 20:22
Status:active» postponed (maintainer needs more info)

Well, first of all. The code you posted has an error:
Fatal error: Call to undefined function beep_nultiple_beep_action_form()

I changed that to beep_multiple_beep_action_form, then I saw your last function is misspelled.

I was able to run the configure form without problems on my setup. So, can you write a step-by-step guide to recreating the problem.

#3

TapocoL - December 22, 2008 - 18:36
Status:postponed (maintainer needs more info)» closed

No longer supporting AJAX Validation (use AJAX Forms).

 
 

Drupal is a registered trademark of Dries Buytaert.