简体   繁体   English

MODx Evo中的eForm:如何预选择带有数据库值的选择框?

[英]eForm in MODx Evo.: How to preselect select box with database value?

I am able to fill input fields with values (strings) using the $fields[] array in a function I call using [!eForm? 我可以在使用[!eForm?]调用的函数中使用$ fields []数组用值(字符串)填充输入字段。 ... &eFormOnBeforeFormParse ... !]. ...&eFormOnBeforeFormParse ...!]。 I tried to submit a string value to the select box, but this does not work. 我尝试将字符串值提交到选择框,但这不起作用。 I guess that the select box is an array instead of strings. 我猜选择框是一个数组而不是字符串。 I did not find a documentation about the structure of this array or how I can control it. 我没有找到有关此数组的结构或如何控制它的文档。

So my question is: How can I preselect the select box based on the data I find in my database? 所以我的问题是:如何根据在数据库中找到的数据预先选择选择框?

I appreciate any help. 感谢您的帮助。 (Your answer does not need to contain database calls, though.) (不过,您的答案不需要包含数据库调用。)

Just figured it out myself: 我自己才知道:

Select boxes allow multiple selections. 选择框允许进行多项选择。 I forgot about this, because you do not see this very often. 我忘记了这一点,因为您很少看到这种情况。 Therefore, the value has to be an array to allow multiple selections. 因此,该值必须是一个数组以允许多个选择。 So when you have one pre-selection, wrap it in an array. 因此,当您有一个预选时,将其包装在一个数组中。 For instance: 例如:

$fields['state']=array('CA'); $ fields ['state'] = array('CA');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM