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

select中使用ajax返回提示信息的问题

赞成!
0
否决!
$form['forbid_user_select'] = array(
			'#type' => 'select',
			'#options' =>array('禁言','禁言3天','禁言7天','禁言10天'),
			'#submit' => array('og_actions_forbid_user_submit'),
			'#ajax' => array(
					'event'=>'change',
					'callback' =>'og_actions_forbid_user_select',
					'wrapper' => 'user_submit_wrapper',
			),
function og_actions_forbid_user_select($form, $form_state){
	$form['results']['#markup'] = "禁言成功";
	return $form;
}


请看看上述代码,请教一下,如果通过ajax执行完毕后,可以返回一个提示信息呢?我希望显示在drupal_set_message显示信息的那个位置,谢谢了。

3 个回答

赞成!
0
否决!

drupal_set_message 跟ajax是比较难一起了,试想下,ajax目的是无刷新,而drupal_set_message是要重写load页面。

你可以试一下下面方法:

// Remove the old messages div, clearing existing messages.
  $commands[] = ajax_command_remove('#messages');
  // Append a new messages div with our latest errors and messages.
  $commands[] = ajax_command_after('#header-region', '<div id="messages">' . theme('status_messages') . '</div>');
赞成!
0
否决!
$form['ld']['letterdrop_allocations_submit'] = array(
     '#type' => 'submit',
     '#value' => 'Letterdrop allocations update',
     //        '#name' => 'Letterdrop allocations update',
     '#name' => 'agc_letterdrop_submit',
     '#ajax' => array(
       'callback' => 'agc_ems_form_letterdrop_submit_ajax',
       ),
     );

 ...

function agc_ems_form_letterdrop_submit_ajax($form, &$form_state) { 
  drupal_set_message('here i am world', 'ok'); 
  $commands = array(); 
  $commands[] = ajax_command_replace('#messages', 
      '<div id="messages">' . theme('status_messages') . '</div>'); 
  $commands[] = ajax_command_alert('submitted via handler'); 
  return array( 
      '#type' => 'ajax', 
      '#commands' => $commands); 
} 
赞成!
0
否决!

好的,谢谢两位兄弟提供的思路,呵呵