2010-10-11 35 views
1

這工作...緬懷笨form_dropdown領域

form_dropdown('location', $location_options, $this->input->post('location')); 

但是當我嘗試使用數組來增加額外的屬性,它停止工作......這是爲什麼呢?

$attributes = array(
    'name' => 'location', 
    'id' => 'location' 
); 

form_dropdown($attributes, $location_options, $this->input->post('location')); 

下拉列表的名稱包含屬性的陣列中,所以我看不出這是任何不同的第一個例子。每當表單發佈回來時,它都會重置爲開始。

任何人都可以幫我解決這個問題嗎? 謝謝

回答

1

這只是錯誤的語法。

請看看在實況:http://codeigniter.com/user_guide/helpers/form_helper.html

form_dropdown('location', $location_options, $this->input->post('location'), "id='location'"); 

你的代碼應該看起來像上面。順便說一句:如果你使用form_validation庫,你可以使用SET_VALUE而不是$這個 - >輸入 - >後...

+0

好吧,看起來像錯誤的語法...不解釋如何傳遞一個屬性數組,並仍然保留在「form_input」字段的值,但不能做一樣的「 form_dropdown「字段而不會丟失發佈數據。 – Quigley 2010-10-11 03:52:08

+0

您將您的屬性作爲字符串添加爲form_dropdown()的最後一個參數。 – mseo 2010-10-11 11:35:56

+2

重要提示:爲了在使用表單驗證庫時工作,set_value()必須是驗證規則的一部分。 – 2011-12-09 00:04:55

0
$attributes = ' id="bar" class="foo" onChange="some_function();"'; 
    $location_options = array(
     'IN' =>'India', 
     'US' =>'America' 
    ); 

form_dropdown('location', $location_options, $this->input->post('location'),$attributes); 

參數:

  1. 1 PARAM會分配給字段的名稱,
  2. 第二會得到你的選擇,
  3. 第三是默認值,
  4. 第四屆一個是額外的屬性添加像JavaScript函數,身份證,類...