在 drupal 中获取更改后的表单值
我以 drupal 名称创建了一个模块作为 newmodule。我使用 form alter 来更改用户注册表单以添加一个字段位置。当我提交表单时,我如何获取我创建的新字段的值。
I created one module in drupal name as newmodule.I use form alter to alter user registration form for adding one field location.When i submit the form, how i can get the value of the new field which i created .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为了详细说明前面的答案,在您的 hook_form_alter 函数中的某处,您想要告诉表单运行您自己的 #submit 处理程序,例如:
注意:您应该在此处附加 #submit,而不是替换它。然后在您的提交处理程序中,您可以轻松获取该值,例如:
To elaborate on the previous answers, somewhere in your hook_form_alter function, you want to tell the form to run your own #submit handler, e.g.:
Note: you should be appending on #submit here, not replacing it. Then in your submit handler, you can get the value easily, e.g.:
表单值
默认存储在中。如果将
#tree
设置为TRUE
,此行为将会改变,并且值将位于嵌套数组中,而不是平面数组中。将调用两种类型的函数,您可以在其中访问
$form_state
变量。验证函数用于验证表单数据,检查用户输入的数据是否可接受,例如有效的电子邮件地址等。要添加验证函数,请将其添加到表单更改实现中:
提交函数用于对包含有效数据的表单进行操作。通常,您将数据插入数据库,在此处设置重定向等,以添加提交功能,将其添加到您的表单更改实现中:
验证和提交函数都采用相同的参数:
The form value is stored in
By default. If you set
#tree
toTRUE
this behavior will change, and the values will be in a nested array instead of a flat one.Two type of functions will be called, where you have access to the
$form_state
variable.Validation functions is used validate the form data, to check if the user inputted data is acceptable, like a valid email address etc. To add a validation function add this in your form alter implementation:
Submit functions is used to act upon a form with valid data. Typically you insert data into the database, set redirects and such here, to add a submit function add this in your form alter implementation:
Both validation and submit functions take the same args:
新模块还需要调用 _submit 挂钩,以便您可以转储 $form 和 $form_state 值,以便可以看到它们。
New module also needs a _submit hook invoked so you can dump out the $form and $form_state values so you can see them.