首页 > 解决方案 > 如何在 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');

标签: drupaldrupal-7

解决方案


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
}

推荐阅读