Drupal表单提交,表单after_build
$form['#submit']
和 $form['#after_build']
有什么区别?
What is the difference between $form['#submit']
and $form['#after_build']
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
api 文档对此进行了很好的阐述。
$form['#submit']
会将提交处理程序数组添加到您的表单中:即,当有人单击“提交”按钮时,将调用数组中的函数。这些将在提交后调用。当您调用
hook_form_alter()
将另一个提交函数添加到您没有自己构建的表单上时,您通常会希望使用此属性,就像您自己在代码中创建表单一样,您还创建默认的提交处理程序。此处是 FAPI 文档在
#submit
上。$form['#after_build']
类似,它需要调用一组函数,但它们将在构建用于显示的表单后调用。如果您在表单元素中有默认值或现有值,并且想要在提交之前检查具有该值的内容的状态,则可以使用此功能。请参阅 FAPI 文档以获取良好的信息在提交之前、在构建要显示的表单之后检查某些内容的状态的示例。总之,
$form['#submit']
函数将在提交时调用,而$form['#after_build']
函数将在显示时调用形式。The api docs lay this out fairly well.
$form['#submit']
will add an array of submit handlers to your form: ie when someone clicks the "Submit" button the function in the array will be called. These will be called after submission.You generally would want to use this property when you are calling
hook_form_alter()
to add another submit function on to a form that you didn't build yourself, as if you create the form yourself in code, you also create the default submit handler.Here are the FAPI docs on
#submit
.$form['#after_build']
is similar in that it takes an array of of functions to call, but they will be called after the form is built for display. This can be used if you have a default or existing value in a form element, and want to check the status of something with that value before submission. See the FAPI docs for a good example of checking the status of something before submission, after the form is built to be displayed.So in summary,
$form['#submit']
functions will be called upon submission, and$form['#after_build']
functions will be called upon display of the form.