Drupal保存数据hook_form_alter
我使用 hook_form_alter 添加了一个字段到节点,我可以看到它很好,但现在我当然希望在该字段中输入的数据也被保存。我必须做什么才能发生这种情况?
I added a field to a node using hook_form_alter and i can see it fine but now i would like of course that the data enterd in that field is also saved. What do i have to do for this to happen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您更改表单时,您还需要向模块添加表单提交处理程序;这样,您的模块将在提交表单时被调用,并且您可以保存您添加的字段的值。
如果有多个按钮,那么最好将提交处理程序添加到您需要执行操作的特定按钮。例如,假设表单有两个提交按钮:“保存”和“删除”;如果您使用
$form[#submit][] = "my module_form_submit";
添加提交处理程序,那么即使单击“删除”按钮也会调用提交处理程序。正如表单按钮可以定义自定义#submit 和#validate 处理程序中所述:
此外,表单值中的“op”元素已弃用,不应依赖报告:
When you alter the form, you need to also add a form submission handler to the module; in that way, your module would be invoked when the form is being submitted, and you can save the value of the field you added.
If there are more than one button, then it's preferable to add the submission handler to the specific button you need to act upon. Suppose, for example, that the form has two submission buttons: "Save" and "Delete"; if you add the submission handler with
$form[#submit][] = "my module_form_submit";
then the submission handler is called even when the "Delete" button is clicked.As reported in Form buttons can define custom #submit and #validate handlers:
Additionally, The 'op' element in the form values is deprecated and should not be relied upon reports: