在 Drupal Forms API 表单的验证函数中,我尝试从用户的信用卡中扣款。如果成功,我想将引用号传递给提交函数,以便在那里使用。这样做的最佳方法是什么?
最佳答案
documentation说这个:
Note that as of Drupal 6, you can also simply store arbitrary variables in $form['#foo'] instead, as long as '#foo' does not conflict with any other internal property of the Form API.
所以你可以做这样的事情:
function form($form_state) {
//in your form definition function:
$form['#reference_number'] = 0;
}
function form_validate($form, &$form_state) {
//try to charge card ...
if ($card_charged) {
$form_state['values']['#reference_number'] = $reference_number;
}
}
function submit_form($form, &$form_state) {
if (isset($form_state['values']['#reference_number'])) {
$reference_number = $form_state['values']['#reference_number'];
//do whatever you want
}
}
关于drupal - 将信息从 Drupal Forms API 验证函数传递到提交函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1208347/