获取php Drupal Form中选项的值
更新
我已经使用 Form API 制作了一个 Drupal Form。我使用了元素选择,我的问题如何获取用户选择的值? 例如:以下代码。我如何知道用户为“Titles plus teaser”(预告片)选择了什么。谢谢!
form ['planning_detail']['study_groep'] = array (
'# type =' select ',
'# title' = 'Pick a value',
'# options' => array (
'title' => t ('Titles only '),
'teaser' => t ('Titles plus teaser'),
'full text' => t ('Full text '),
)
);
update
I have made a Drupal Form with the Form API. I used a the element select, my question how can I get the value that the user chose?
For the example: the following code. How can I know what the user chose for 'Titles plus teaser' (teaser). Thanks!
form ['planning_detail']['study_groep'] = array (
'# type =' select ',
'# title' = 'Pick a value',
'# options' => array (
'title' => t ('Titles only '),
'teaser' => t ('Titles plus teaser'),
'full text' => t ('Full text '),
)
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要为您的表单创建一个表单提交处理程序。您可以通过创建一个名为
FORMNAME_submit
的函数来完成此操作:form_state 是一个数组,其中包含有关表单状态的大量信息,并且还包含已提交的所有值。默认情况下,它们位于由表单元素的字段名称键入的平面列表中。提交句柄是您通常处理用户提交的数据的地方,例如将其保存到数据库等。表单还有一个将在提交处理程序之前调用的验证。使用表单 API,如果用户输入未验证,则可能会产生表单错误。当使用 API 创建错误时,在验证步骤中,不会调用提交函数。这意味着您将知道,当调用提交函数时,数据没有错误。
更新:
如果您想要向用户显示的值,您可以通过访问验证/提交处理程序中提供的表单数组来访问该值。我在上面的例子中已经展示了这一点。
You need to make a form submit handler for your form. You can do this by creating a function called
FORMNAME_submit
:The form_state is an array that contains a lot of info about the state of the form, and it also has all the values that was submitted. They are by default in a flat list keyed by the field name of the form element. Submit handles is where you typical process the data the user submitted, like saving it to the database etc. Forms also has a validate that will be called before the submit handler. With the form API it's possible to create form errors if the user input doesn't validate. When an error is created with API, in the validate step, the submit function wont be called. This means you will know that when the submit function is called, that the data is error free.
Updated:
If you want to value that is displayed to the user, you can access that, by accessing the form array that is supplied in validate/submit handlers. I have shown this in the example above.
正确的属性“#options”必须位于“”中
The correct attribute '#options' must in ''
假设您将这些选项放入选择列表中,
您可以像这样访问该值
Assuming you have those options placed into a select list
you can acces the value like this