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

请问ajax不能这样提交来添加node并插入og模块吗?

赞成!
0
否决!
	$form['editor_views'] = array(
			'#type' => 'submit',
			'#value' => '发表',
			'#attributes' => array('class' => array('editor_views')),
			'#ajax' => array(
					'callback' => 'og_blocks_send_node_ajax_callback',
					'wrapper' => 'editor_wrappers',
					'method' => 'replace',
					'effect' => 'fade',
			),
	);

function og_blocks_send_node_ajax_callback($form, $form_state){
	$node_title = trim($form_state['values']['node_title']);
	$editor_box = trim($form_state['values']['editor_box']['value']);
	$gid = trim($form_state['values']['gid']);
	if (!empty($editor_box) && !empty($node_title) && !empty($gid)) {
		global $user;
		$uid = $user->uid;
		$node = new stdClass(); 
		$node->type = 'group content'; 
		$node->title =  check_plain($node_title);
		$node->language = LANGUAGE_NONE; 
		$node->uid = $uid; 
		$node->body [LANGUAGE_NONE] [0] = array (
			'value' =>  $editor_box,
	   );
		node_save($node);
                $node = node_submit($node);
		$values = array(
				'entity_type' => 'node',
				'entity' => $node,
				'state' => OG_STATE_ACTIVE,
		);
		og_group('node', $gid,$values);
		return '发布成功 !';
	}
	else {
		return $form;
	}
}

 

源码如上,但老是报各种各样的错误,我怀疑写错地方了,请各位成功运用过的同学帮我看看,要如何改,或者应该放在哪里?

谢谢!

2 个回答

赞成!
0
否决!

drupal_write_record 一定可以

赞成!
0
否决!

已用另外的方法解决,谢谢