Drupal 7 开发内部培训资料, 分头诗人

自己定义的表单,同模块下的函数怎么接受post过来的数据

赞成!
0
否决!

aa()怎么接受 表单formexample_nameform post过来的参数?怎么判断有传参数过来?
 

<?php
/**
* @file
* Play with the Form API.
*/
/**
 * Implements hook_menu().
 */
function formexample_menu() {
	$items ['formexample'] = array (
			'title' => 'the sample form',
			'page callback' => 'drupal_get_form',
			'page arguments' => array (
					'formexample_nameform' 
			),
			'access callback' => TRUE,
			'type' => MENU_NORMAL_ITEM 
	);
	return $items;
}
/**
 * Define a form.
 */
function formexample_nameform() {
	$form ['user_name'] = array (
			'#title' => t ( 'Your Name' ),
			'#type' => 'textfield',
			'#description' => t ( 'Please enter your name.' ) 
	);
	$form ['submit'] = array (
			'#type' => 'submit',
			'#value' => t ( 'Submit' ) 
	);
	return $form;
}
/**
 * Validate the form.
 */
function formexample_nameform_validate($form, &$form_state) {
	if ($form_state ['values'] ['user_name'] == 'King Kong') {
		// We n0tify the form API that this field has failed validation.
		form_set_error ( 'user_name', t ( 'King Kong is not allowed to use this form.' ) );
	}
}
/**
 * Handle post-validation form submission.
 */
function formexample_nameform_submit($form, &$form_state) {
	$name = $form_state ['values'] ['user_name'];
	drupal_set_message ( t ( 'Thanks for filling out the form, %name', array (
			'%name' => $name 
	) ) );
}

function aa(){
	/*这个函数怎么接受post过来的参数?
	 * */
	
}

1 个回答

赞成!
0
否决!

纠正下,formexample_nameform() 写错了,最好是formexample_nameform($form, &$form_state)

aa() 收到信息可以这么做:

/**
 * Handle post-validation form submission.
 */
function formexample_nameform_submit($form, &$form_state) {
    $name = $form_state ['values'] ['user_name'];
    drupal_set_message ( t ( 'Thanks for filling out the form, %name', array (
            '%name' => $name
    ) ) );
    aa($name);
}
 
function aa($sth){
    /*这个函数怎么接受post过来的参数?
     * */
    print $sth;
   }