I'm writing a custom module which needs to send data string like this: "CODES[]=xxx&NAMES[]=xxx" via POST to 3rdparty payment gateway AND redirect user there.
I've written a form to gather data from customer, but I can't use [] in form fields names, Drupal reports an error (an array instead of string) and quits.
I can post all data manually via drupal_http_request, but it doesn't redirects browser to needed URL. If I use drupal_goto after drupal_http_request, the data is lost and payment service doesn't recognize the user. If I include $request(my drupal_http_request)->result in a page, I get redirected to 404 page of my site with a non-existent URL (/order/checkout.php which has to be appended to payment server root and instead glues to my server root URL).
If I use $form['#redirect'] or $form['#action'] it posts fields names without "[]".
Question is, how can I append these square brackets after request is formed, but before it is sent?
Or how can I send data along with redirecting?
Will be very grateful for help, this problem is driving me nuts for a week now.
UPD My code:
//a form
function mymodule_ask(&$form_state) {
$form = array();
$form['#action'] = 'https://3rdpartysite.url/script.php';
$form['#method'] = 'post';
$form['ORDER_PRICE[]'] = array(
'#type' => 'textfield',
'#title' => t('Amount'),
'#size' => 10,
'#required' => TRUE
);
$form['ORDER_PNAME[]'] = array (
'#type' => 'radios',
'#title' => t('Name'),
'#options' => array('Avia' => 'Avia tickets', 'Other' => 'Other'),
'#required' => TRUE
);
$form['submit'] = array (
'#type' => 'submit',
'#value' => t('PAY')
);
return $form;
}
function mymodule_ask_submit {
//in form submit function retrieving data from form values
$requestar['ORDER_PNAME[]'] = $form_state['values']['ORDER_PNAME'];
$requestar['ORDER_PRICE[]'] = $form_state['values']['ORDER_PRICE'] * 1.02;
//forming an array to post
$onestr = '';
foreach ($requestar as $key => $value) {
$onestr .= $key."=".$value."&";
}
$resstr = chop($onestr, '&');
// and then I tried different ways
//either creating and auto-submitting a form with needed values
create_form($requestar); //separate function creating this form
drupal_execute('payu_addform', $form_state);
// but it doesn't pass drupal evaluation because of "ORDER_PRICE[]" element name
//or via http_request
$result = drupal_http_request('https://PAYMENT_SERVER_URL/script.php', array('Content-Type' => 'application/x-www-form-urlencoded'), 'POST', $resstr);
drupal_set_message($result->request);
// but it takes me to MY_SERVER_URL/order/checkout.php?CART_ID=442bc42170616cd36dfd2246434d4210, while I need it to make to PAYMENT_SERVER_URL/order/checkout.php?bla-bla-bla
//may be I can use $result->request in some other way? Just printing within this submit function gives nothing... But how can I pass it to make drupal take me out?
}
$form['#action']
method is the only possible solution.