2016-02-22 86 views
2

所以,我在Joomla的RSForm Pro中有這個註冊表單,在那裏我有兩個下拉列表。一個從mySQL獲取美國國家和一個從該州獲取城市/縣的人。問題是,我不知道如何檢查用戶在第一個下拉列表中選擇的狀態。我找到了一種手動方式(爲每個狀態創建一個列表),但這不夠好。它應該自動完成。Joomla RSForm Pro Dynamic Dropdown

請幫忙!

這是我用來填充第一個下拉列表(包含狀態)的一段代碼。這放在RSForm Pro的「項目」字段中:

//<code> 
     $interestedstates = array(); 
     $db = JFactory::getDbo(); 
     $interestedstates[] = "|Please Select[c]"; 

     $db->setQuery("SELECT id, state_name FROM #__osrs_states"); 
     $results = $db->loadObjectList(); 

     foreach ($results as $result) { 
     $value = $result->id; 
     $label = $result->state_name; 
     $interestedstates[] = $value.'|'.$label; 
     } 
     $interestedstates = implode("\n", $interestedstates); 

     return $interestedstates; 
    //</code> 

非常感謝!

回答

0

This post通過RSForm Pro應該派上用場。但是,這意味着您必須預先加載JavaScript中的所有值 - 我不確定是否要這樣做。

另一種選擇是通過Ajax加載值。沒有樂趣,但是考慮到美國每個州有很多城市的情況,這是一個更好的選擇。