Startseite
  • » Home
  • » Handbuch & FAQ
  • » Forum
  • » Übersetzungsserver
  • » Suche
Startseite › Forum › Drupalcenter.de › Module › Modul-Entwicklung ›

ahah: mehrere Form-Elemente bei Select-change ändern

Eingetragen von jeho (3)
am 07.05.2009 - 12:39 Uhr in
  • Modul-Entwicklung
  • Drupal 6.x

Hallo Leute!

Ich habe hier ein Registrierungs-Formular in einem eigenen Modul "custom" mit 4 Selects, die von einander abhängig sind:
Firma -> Land -> Stadt -> Adresse
Wenn ich eine Firma auswähle, wird per ahah das Land-Select gefüllt. Wenn ich dann ein Land auswähle, erhält das Stadt-Select entsprechende Einträge etc.

Mein Problem nun: Habe ich alle 4 gewählt und wähle dann eine andere Firma, müssen Stadt und Adresse geleert werden bzw. mit "---" gefüllt (Land wird ja schon durch ahah gefüllt). Bei Auswahl eines Landes muss entsprechend das Adress-Select geleert werden.

Wie setzte ich das nun in meiner Funktion um? Habe schon diverse Ansätze versucht, nichts klappt. Hier die Funktion, die nach der Firmenwahl das Land-Select füllt:

<?php

function custom_registration_get_company_countries_js()
{
   
// Get the new values
   
$new_company_countries = custom_registration_get_company_countries($_POST['company']);

   
// Get form from cache and store modified place selection
   
$form_state = array('storage' => NULL, 'rebuild' => TRUE);
   
$form = form_get_cache($_POST['form_build_id'], $form_state);
 
   
// Select neu setzen
   
$form['account']['country'] = array(
       
'#type' => 'select',
       
'#title' => t('Country'),
       
'#required' => TRUE,
       
'#options' => $new_company_countries,
       
'#description' => t('Helptext for the agencies country select'),
       
'#weight' => 11,
    );

   
form_set_cache($_POST['form_build_id'], $form, $form_state);
   
$form += array(
       
'#post' => $_POST,
       
'#programmed' => FALSE,
    ); 
 
   
// Rebuild the form.
   
$form_state = array('submitted' => FALSE);
   
$form = form_builder('user-register', $form, $form_state);

   
// Render the new output.
   
$output = theme('status_messages') . drupal_render($form['account']['country']);

   
// Don't call drupal_json(). ahah.js uses an iframe and
    // the header output by drupal_json() causes problems in some browsers.
   
print drupal_to_js(array('status' => TRUE, 'data' => $output));
    exit;
}
?>

Hier müsste also irgendwie sowas rein:

<?php

   $form
['account']['city']['#options'] = array('0' => '---');
  
$form['account']['agencies_addresses']['#options'] = array('0' => '---');
?>

Ich habe auch schon versucht, das Element einfach anzuhängen. Das geht zwar, aber dann ist die Select-Box (logischereise) zweimal vorhanden, weil sie jetzt in einem anderen Wrapper gerendert wird.

<?php

function custom_registration_get_company_countries_js()
{
   
$new_company_countries = custom_registration_get_company_countries($_POST['company']);

   
// Get form from cache and store modified place selection
   
$form_state = array('storage' => NULL, 'rebuild' => TRUE);
   
$form = form_get_cache($_POST['form_build_id'], $form_state);
 
   
// Select neu setzen
   
$form['account']['country'] = array(
       
'#type' => 'select',
       
'#title' => t('Country'),
       
'#required' => TRUE,
       
'#options' => $new_company_countries,
       
'#description' => t('Helptext for the agencies country select'),
       
'#weight' => 11,
    );
   
$form['account']['city'] = array(
       
'#type' => 'select',
       
'#title' => t('City'),
       
'#required' => TRUE,
       
'#options' => array('0' => '---'),
       
'#description' => t('Helptext for the agencies city select'),
       
'#weight' => 12,
    );

   
form_set_cache($_POST['form_build_id'], $form, $form_state);
   
$form += array(
       
'#post' => $_POST,
       
'#programmed' => FALSE,
    ); 
 
   
// Rebuild the form.
   
$form_state = array('submitted' => FALSE);
   
$form = form_builder('user-register', $form, $form_state);

   
// Render the new output.
   
$output = theme('status_messages') . drupal_render($form['account']['country']) . drupal_render($form['account']['city']);

   
// Don't call drupal_json(). ahah.js uses an iframe and
    // the header output by drupal_json() causes problems in some browsers.
   
print drupal_to_js(array('status' => TRUE, 'data' => $output));
    exit;
}

?>

Kann mir jemand helfen?

Grüße Jens

‹ Private Nachrichten und Rollen Datenbank Update Problem ›
  • Anmelden oder Registrieren um Kommentare zu schreiben

Benutzeranmeldung

  • Registrieren
  • Neues Passwort anfordern

Aktive Forenthemen

  • Best Practices for Plain Text Notes
  • gepatchte PHP Version 7.4 für Windows
  • Canvas Palette: Eine fertige Komponentenbibliothek für Drupal Canvas
  • Hilfe zu Updates oder Composer
  • Vergleich Drupal und Contao
  • [geloest] Blocks in Bootstrap nebeneinander darstellen und nicht untereinander
  • DrupalCamp Frankfurt 27-28 November 2026
  • Bitte mein Bentzerkonto löschen
  • Beim Aufruf einiger Inhalte erhalte ich folgende Fehlermeldung
  • Neuinstallation: vermutlich ein rewrite-Problem
  • Drupal CMS installieren
  • [erledigt]MP3 in Drupal 10 einbinden
Weiter

Neue Kommentare

  • Muss ja nicht genau php 8.3 sein
    vor 1 Tag 6 Stunden
  • Guten morgen und Danke
    vor 1 Tag 13 Stunden
  • Evtl. versuchen auf PHP 8 zu wechseln
    vor 1 Tag 19 Stunden
  • Danke Schmittrich. Die Frage
    vor 3 Tagen 10 Stunden
  • Keine Antwort auf die Frage nach dem Woher
    vor 3 Tagen 13 Stunden
  • Danke ich werde mir die
    vor 6 Wochen 1 Tag
  • Vielen Dank für Ihren
    vor 6 Wochen 4 Tagen
  • Composer ist sehr ratsam
    vor 6 Wochen 5 Tagen
  • Vielen Dank für den
    vor 7 Wochen 1 Tag
  • Die alten CMS Vergleiche von contentmanager.de
    vor 7 Wochen 1 Tag

Statistik

Beiträge im Forum: 250324
Registrierte User: 20571

Neue User:

  • alxshell
  • FesObsemo
  • AnthonyhoF

» Alle User anzeigen

User nach Punkten sortiert:
wla9466
stBorchert6003
quiptime4972
Tobias Bähr4019
bv3924
ronald3857
md3717
Thoor3678
Alexander Langer3416
Exterior2903
» User nach Punkten
Zur Zeit sind 0 User und 11 Gäste online.

Hauptmenü

  • » Home
  • » Handbuch & FAQ
  • » Forum
  • » Übersetzungsserver
  • » Suche

Quicklinks I

  • Infos
  • Drupal Showcase
  • Installation
  • Update
  • Forum
  • Team
  • Verhaltensregeln

Quicklinks II

  • Drupal Jobs
  • FAQ
  • Drupal-Kochbuch
  • Best Practice - Drupal Sites - Guidelines
  • Drupal How To's

Quicklinks III

  • Tipps & Tricks
  • Drupal Theme System
  • Theme Handbuch
  • Leitfaden zur Entwicklung von Modulen

RSS & Twitter

  • Drupal Planet deutsch
  • RSS Feed News
  • RSS Feed Planet
  • Twitter Drupalcenter
Drupalcenter Team | Impressum & Datenschutz | Kontakt
Angetrieben von Drupal | Drupal is a registered trademark of Dries Buytaert.
Drupal Initiative - Drupal Association