我的自定义模块expertsqa.module中有以下代码
function expertsqa_menu() {
$items = array();
$items['expertsqa/answerquestion'] = array(
'title' => 'Answer question', //page title
'description' => 'A form to mess around with.',
'page callback' => 'drupal_get_form',
'page arguments' => array('expertsqa_answer_form'), //put the name of the form here
'access callback' => TRUE
);
return $items;
}
function expertsqa_answer_form($form, &$form_state) {
drupal_add_js(drupal_get_path('module', 'expertsqa') . '/js/jquery.form.js');
$suffix = '
<script>
jQuery(document).ready(function() {
jQuery(\'#expertsqa-answer-form\').ajaxForm({
target: "#output"
});
});
</script>
';
$form['price'] = array(
'#type' => 'textarea',
'#title' => 'Type Answer',
'#rows' => 5,
'#columns' => 10,
'#required' => TRUE,
'#suffix' => $suffix,
);
$form['submit_button'] = array(
'#type' => 'submit',
'#value' => t('Click Here!'),
);
return $form;
}
function expertsqa_answer_form_submit($form, &$form_state) {
drupal_json_output(array('foo', 'baa'));
drupal_exit();
}
我想通过 ajaxform JQuery 插件提交表单的内容,该插件工作正常,然后希望它由应该返回 JSON 响应的函数expertsqa_answer_form_submit 处理。请有人告诉我正确的方法,因为它返回完整的 html