Ich habe Code wie unten geschrieben und alles funktioniert einwandfrei, aber beim Absenden des Formulars wird der folgende Fehler angezeigt. Ich versuche, das zweite Dropdown basierend auf der ersten Dropdown-Auswahl zu filtern.
Eine illegale Auswahl wurde festgestellt. Bitte wenden Sie sich an den Site-Administrator.
Wie überwinde ich diesen Fehler?
function dynamic_location_dropdown_form_alter(&$form, $form_state, $form_id) {
if($form_id == 'product_node_form') {
$location_options = array();
if(isset($form['field_destination']['und']['#default_value'][0])) {
$destination = $form['field_destination']['und']['#default_value'][0];
}
else {
$destination = 0;
}
$location_options = dynamic_location_dropdown_locations($destination);
$form['field_destination']['und']['#ajax'] = array(
'event' => 'change',
'wrapper' => 'squadron-wrapper',
'callback' => 'dynamic_location_dropdown_ajax_callback',
'method' => 'replace',
);
$form['field_product_location']['#validated'] = true;
$form['field_product_location']['und']['#prefix'] = '<div id="squadron-wrapper">';
$form['field_product_location']['und']['#suffix'] = '</div>';
$form['field_product_location']['und']['#options'] = $location_options;
}
}
function dynamic_location_dropdown_ajax_callback($form, $form_state) {
$country_id = $form['field_destination']['und']['#value'];
$form['field_product_location']['#validated'] = true;
$form['field_product_location']['und']['#options'] = dynamic_location_dropdown_locations($country_id);
return $form['field_product_location'];
}
function dynamic_location_dropdown_locations($destination_id) {
$nodes = array();
$nodes[''] = '- None -';
if($destination_id != '') {
$select = db_query("
SELECT node.title AS node_title, node.nid AS nid, node.created AS node_created
FROM {node} node
LEFT JOIN {field_data_field_location_country} field_data_field_location_country
ON node.nid = field_data_field_location_country.entity_id
AND (field_data_field_location_country.entity_type = 'node'
AND field_data_field_location_country.deleted = '0')
WHERE (( (node.status = '1')
AND (node.type IN ('location'))
AND (field_data_field_location_country.field_location_country_nid = $destination_id)))
ORDER BY node_title ASC
");
$nodes[''] = '- None -';
foreach ($select as $node) {
$nodes[$node->nid] = $node->node_title;
}
}
return $nodes;
}
'#validated' => TRUE
was sich darum kümmern sollte. Ich vermute also, dass Sie in einigen Eigenschaften den Schlüssel 'und' haben und nicht in dem Formulararray, in dem Sie den Schlüssel '#validated' verwenden ...?