我是在Drupal中创建表单的自称新手。我在Drupal 7网站上托管了一个表单(使用webform模块),并且需要将表单值提交到外部url。我已经研究了一段时间,并编写了一个自定义模块,该模块使用webform模块使用hook_form_alter和自定义提交处理程序/函数(下面粘贴的代码)在外部进行提交。
我一直在使用以下页面作为指南,但无法使该表格正常工作:https : //drupal.org/node/1357136使用drupal_http_post()提交到外部站点:我在做什么错误?
有人可以让我知道我走的路是否正确吗?任何指导都会有所帮助!
<?php
function webform_extra_form_alter(&$form, &$form_state, $form_id)
{
//only want form with nid 1171 to submit externally
//Note that "webform_client_form_1171" means modify the Webform form for the node with NID "1171". Adjust to match whichever webform node's form you're modifying
if($form_id == 'webform_client_form_1171')
{
$form['#action'] = url('https://[url path to external site]');
$form['#attributes'] = array('enctype' => "application/x-www-form-urlencoded");
$form['#submit'][] = 'webform_extra_submit';
}
}
// Adds a submit handler/function for the app signup form (Webform ID #1171)
function webform_extra_submit($form, &$form_state)
{
// Changes can be made to the Webform node settings by modifying this variable
//$form['#node']->webform;
// Insert values into other database table using same input IDs as external db
$option['query'] = array(
$firstName => $form_state['values']['firstName'],
$lastName => $form_state['values']['lastName'],
$email => $form_state['values']['email'],
$name => $form_state['values']['name'],
$phone => $form_state['values']['phone'],
);
$url = url('https://[url path to external site]', $option);
$form_state['redirect'] = $url;
//$form['#action'] = url('https:[url path to external site]');
//$url = 'https://[url path to external site]';
//$headers = array('Content-Type' => 'application/x-www-form-urlencoded',);
//$response = drupal_http_request($url, $headers, 'POST', http_build_query($form_state['values'], '', '&'));
}
?>