Javascript 如何通过AHAH Drupal 6传递争论?
我正在尝试创建一个模块来分析用户内容,并使用第三方API对其进行评分。以下是基本逻辑:模块将文章标题和内容传递给API,API返回显示在编辑节点页面上的结果。到目前为止,这一切都很好 现在我正试图通过AHAH来完成这件事。当用户单击按钮时,它应该立即显示API结果。问题是如何通过AHAH将标题和内容传递给API?在此之前,我可以调用另一个php函数并将标题和文章内容作为函数参数传递 这是我到目前为止所拥有的 hook_form_alter,用于编辑节点表单并添加按钮以触发AHAHJavascript 如何通过AHAH Drupal 6传递争论?,javascript,php,drupal,drupal-6,drupal-modules,Javascript,Php,Drupal,Drupal 6,Drupal Modules,我正在尝试创建一个模块来分析用户内容,并使用第三方API对其进行评分。以下是基本逻辑:模块将文章标题和内容传递给API,API返回显示在编辑节点页面上的结果。到目前为止,这一切都很好 现在我正试图通过AHAH来完成这件事。当用户单击按钮时,它应该立即显示API结果。问题是如何通过AHAH将标题和内容传递给API?在此之前,我可以调用另一个php函数并将标题和文章内容作为函数参数传递 这是我到目前为止所拥有的 hook_form_alter,用于编辑节点表单并添加按钮以触发AHAH functio
function ar_form_alter(&$form, &$form_state, $form_id) {
$title = $form['title']['#default_value'];
$content = $form['body_field']['body']['#default_value'];
$form['arPost']['aranalyze'] = array(
'#type' => 'image_button',
'#src' => drupal_get_path('module', 'ar') . '/inc/images/analyze-button.png',
'#description' => t("Click to score this content."),
'#prefix' => '<div id="ax">',
'#suffix' => '</div>',
'#weight' => 30,
'#ahah' => array(
'path' => 'admin/settings/getscore',
'method' => 'after',
'wrapper' => 'ax',
),
);
}
这是模块调用API并返回HTML结果以显示的地方
function ar_test() {
// should be function ar_test($title, $content){
// Should pass $article and $content to another php function to initiate the call
// $output = ar_api_call($title, $content);
print drupal_json(array('status' => TRUE, 'data' => $output));
}
现在我需要找到一种方法将数据(作为参数)从hook\u form\u alter传递到ar\u test函数
请告知。您应该能够从
$\u POST
超全局变量访问表单值。以下是解决方案:
来自hook_form_alter()
从hook_菜单()
getsore/%符号%接受作为hook\u form\u alter传递的值,并通过page argument将其发送到page\u回调
然后简单地接受论点作为
ar_test($var=0)
干杯谢谢斯克罗尼德。如果你提供一个例子,这可能吗。然而,从这篇有用的文章中,我能够完成我在这个问题上提出的问题:然而,我遇到了另一个问题。本教程向我展示了如何通过一次辩论,但我需要通过两次。试图解决它。
'#ahah' => array(
'path' => 'getscore/'.$value_variable,
$items['getscore/%'] = array(
'page callback' => 'ar_test',
'access arguments' => array('access content'),
'page arguments' => array(1),
'type' => MENU_CALLBACK,
);
return $items;
ar_test($var=0)