You are here

寻找一个提交函数

老葛的Drupal培训班 Think in Drupal

通过将表单的#submit属性设置为一个数组,其中以函数名为键,这里的函数名就是用来处理表单提交的函数的名字,从而为表单分配一个提交函数:
 
// Call my_special_submit_function() on form submission.
$form['#submit'][] = 'my_special_submit_function';
// Also call my_second_submit_function().
$form['#submit'][] = 'my_second_submit_function';
 
    如果表单没有名为#submit的属性,那么接下来就要寻找名为“表单ID”+“_submit”的函数。所以,如果表单ID为user_register,那么Drupal将把#submit属性设置为它所找到的表单处理器函数;也就是user_register_submit。

Drupal版本:

评论

建议:Page 225

其中以函数名为键,” 应该为:”其中函数名为值,“(键什么的无所谓,但是觉得这里这么写,容易跟上一页的'键为函数名,值为数组'混淆;不过看例子就什么都明白了...)

原文是:“The function that handles form  submission can be assigned by setting the #submit property in the form to an array with the name of the function that will handle form submission:”

// Call my_special_submit_function() on form submission.
$form['#submit'][] = 'my_special_submit_function';
// Also call my_second_submit_function().
$form['#submit'][] = 'my_second_submit_function';