drupal - 如何在 Drupal 7 中找到处理提交按钮的文件
问题描述
我是 Drupal 7 的新手,与原生 PHP、MVC 框架、Node.js、.Net 等传统编程相比,这对我来说很奇怪。请帮助我找到处理提交按钮的文件和/或函数。我已经有了这个 tpl 文件
<form id="com_id" method="post" action="">
...
<button type="submit" id="saveBtn" class="hidden btn-save" name="btnSave"><?php echo t('SAVE'); ?></button>
如您所见,表单的操作没有任何价值。在 Laravel MVC 中,这很容易,
Route::get('/the_path', 'RoutinesController@theMethod');
解决方案
1.创建自定义模块
2.在其中创建一个表单示例:
function mymodule_example_form($form, &$form_state) {
//build your form using the form api documentation, linked example and your needs
}
3.为表单添加验证:
function mymodule_example_form_validate($form, &$form_state) {
//your validation goes here
}
4.添加提交功能
function mymodule_example_form_submit($form, &$form_state) {
//do stuff on submit here
}
不确定要在哪里打印,但您始终可以将其放在自定义块中并从那里渲染或使用钩子(mymodule_node_view)将其附加到节点有很多方法,但如果您需要更多详细信息,请具体说明,我们将提供帮助你出去了,不要忘记在创建模块后打开它:)
更新:如果表单已经存在,请使用钩子表单更改:
function your_module_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'your_form_ID') {
$form['#submit'][] = 'your_module_custom_form_submit';
}
function your_module_custom_form_submit(&$form, &$form_state, $form_id) {
//do stuff here on submit
}
推荐阅读
- arrays - 使用 map 在数组中创建出现的哈希值
- angular - 在延迟加载模块中使用子组件
- reactjs - 将拆分表列值反应到不同的行
- concourse - 使用来自文件的动态标签在 Concourse 中使用旧版本的 github-release-resource
- amazon-web-services - 在 provider.tf 中使用多个配置文件而不交换环境变量?
- javascript - ReactJS 未定义 onClick 属性
- android - 使用 mac80211_hwsim 内核模块在 android 模拟器中模拟 WiFi 设备
- r - 在 docker 中运行 RMarkdown 脚本(输出 pdf)时,以端口 8000 作为端点,使用 plot_grid 制作的绘图会在它们周围出现灰色边框
- jquery - jQuery - 隐藏/显示相关 div 是否有文本
- node.js - 带有 TypeScript 3 和 MongoDB 的 Node.js Express API 给了我一些逻辑错误