【发布时间】:2014-06-24 13:10:00
【问题描述】:
我正在为 Drupal 7 开发简单的自定义模块,它采用两个数值并在同一页面上提交两个值的显示总和。
我已准备好表单,但尚未完成,但我想在用户提交表单时调用 calculateFunction() 函数,获取参数和总和值...
信息
name = form_test
description = Small module which demo how to create input form in custom module.
core = 7.x
模块 php
<?php
function form_test_menu()
{
$items['formtest'] = array(
'title' => 'Form Test',
'page callback' => 'drupal_get_form',
'page arguments' => array('form_test_form'),
'access callback' => TRUE,
);
return $items;
}
function form_test_form($form,&$form_submit) {
$form['firstname'] = array(
'#title' => t('First Number'),
'#type' => 'textfield',
'#required' => TRUE,
);
$form['lastname'] = array(
'#title' => t('Second Number'),
'#type' => 'textfield',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Run Function'));
calculateFunction($form);
return $form;
}
function calculateFunction()
{
echo "sum of two numbers.....";
}
?>
【问题讨论】:
标签: javascript php drupal-7 drupal-forms