如何在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
}

最新更新