我沒有經驗的PHP。我遵循幾個教程,使用template.php中的主題方法修改我的Drupal表單。修改Drupal表單字段 - [#weight]不被尊重的數組?
由於某些原因,字段的[#weight]屬性不符合其值。我想將Subject字段[subject]上的Category字段[cid]移動。這些是代碼行我用:
$form['cid']['#weight'] = 0.003;
$form['subject']['#weight'] = 0.004;
當我打印我的陣列來查看我看到的值發生了變化,但是當我渲染表單沒有更改。每次修改後,我已經清除了性能緩存。
如果你有興趣,這裏是我的印刷陣列的一個片段:
[subject] => Array
(
[#type] => textfield
[#title] => Subject
[#maxlength] => 255
[#required] => 1
[#post] => Array
(
)
[#programmed] =>
[#tree] =>
[#parents] => Array
(
[0] => subject
)
[#array_parents] => Array
(
[0] => subject
)
[#weight] => 0.004
[#processed] => 1
[#description] =>
[#attributes] => Array
(
)
[#input] => 1
[#size] => 60
[#autocomplete_path] =>
[#process] => Array
(
[0] => form_expand_ahah
)
[#name] => subject
[#id] => edit-subject
[#value] =>
[#defaults_loaded] => 1
[#sorted] => 1
)
[cid] => Array
(
[#type] => select
[#title] => Category
[#default_value] => 1
[#options] => Array
(
[1] => General Enquiries
[2] => Support
)
[#required] => 1
[#post] => Array
(
)
[#programmed] =>
[#tree] =>
[#parents] => Array
(
[0] => cid
)
[#array_parents] => Array
(
[0] => cid
)
[#weight] => 0.003
[#processed] => 1
[#description] =>
[#attributes] => Array
(
)
[#input] => 1
[#size] => 0
[#multiple] =>
[#process] => Array
(
[0] => form_expand_ahah
)
[#name] => cid
[#id] => edit-cid
[#value] => 1
[#defaults_loaded] => 1
[#sorted] => 1
)
大加讚賞,
克里斯
這是有道理的。那麼有沒有辦法解決這個問題?我只需要一個例外就是聯繫表單。我知道我可以主題它,但有沒有編碼修復? – 2010-07-31 10:13:43
@克里斯,是的,沒有。我已經用更多信息和一些可能的解決方案更新了我的答案。 – 2010-07-31 10:38:15
感謝您的解決方案。我瞭解CCK現在如何處理表單字段。我想如果我有一個自定義窗體,那麼我會走這條路線,但因爲我只需要重新排列整個站點範圍內的一個[cid]字段,我只需要使用CSS就可以了。我會記下您的解決方案以備將來參考。非常感謝! – 2010-07-31 10:46:37