Drupal 7 自定义模块 |在设置页面中创建一个调用自定义函数的按钮

发布于 2025-01-05 22:21:38 字数 175 浏览 5 评论 0原文

我创建了一个自定义模块,它有自己的设置页面,管理员可以在其中设置某些参数(单选按钮、输入字段和下拉列表)。

我正在寻找一种在表单中创建一个执行自定义功能的按钮的方法。 (例如:就像管理页面中的“清除所有缓存”按钮一样。)

创建此内容的最简单或最好的方法是什么?

提前致以亲切的问候和感谢!

I've created a custom module with it's own settings page where the administrator can set certain parameters (radio buttons, input fields and dropdown).

I'm looking for a way to create a button in the form that will perform a custom function.
(Example: Like the 'clear all caches' button in the admin page.)

What's the easiest or best way to create this?

Kind regards and thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别念他 2025-01-12 22:21:38

表单上的每个不同按钮都可以通过为其分配 #submit 属性:

function mymodule_my_form($form, &$form_state) {
  $form['button1'] = array(
    '#type' => 'submit',
    '#value' => 'Perform 1st Action',
    '#submit' => array('mymodule_my_form_action_one')
  );

  $form['button2'] = array(
    '#type' => 'submit',
    '#value' => 'Perform 2nd Action',
    '#submit' => array('mymodule_my_form_action_two')
  );
}

function mymodule_my_form_action_one($form, &$form_state) {
  // Perform the 1st action
}


function mymodule_my_form_action_two($form, &$form_state) {
  // Perform the 2nd action
}

每次单击按钮时,只会运行指定的提交函数。

Each different button on your form can perform a different function by assigning it the #submit property:

function mymodule_my_form($form, &$form_state) {
  $form['button1'] = array(
    '#type' => 'submit',
    '#value' => 'Perform 1st Action',
    '#submit' => array('mymodule_my_form_action_one')
  );

  $form['button2'] = array(
    '#type' => 'submit',
    '#value' => 'Perform 2nd Action',
    '#submit' => array('mymodule_my_form_action_two')
  );
}

function mymodule_my_form_action_one($form, &$form_state) {
  // Perform the 1st action
}


function mymodule_my_form_action_two($form, &$form_state) {
  // Perform the 2nd action
}

Only the specified submit function will run for each button click.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文