0

I'm working on a custom module that will allow payments through a particular bank API.

The API requires me to do a POST to a certain URL that they have provided me, where the user will enter his credit card information. To do so, I created a form with the #action set toward the provided URL, and with the mandatory fields asked by the bank (name, address, phone, etc.)

Unfortunatly, the form is in the module, and I don't think that is good practice, since it gets more complicated for a user to add his own custom field (lets say a date of birth for example).

Is there anyway that my module can get a form created by the form API in another module ("my_custom_cart") and add to it the mandatory fields needed for the transaction?

Thank you

1 Answer 1

0

I think using the form #action is the wrong approach there.

You should instead use

drupal_http_request

Performs an HTTP request.

This is a flexible and powerful HTTP client implementation. Correctly handles GET, POST, PUT or any other HTTP requests. Handles redirects.

In your form submit handler, to pass on the required parameters to the payment gateway.

Ensure everything is done under HTTPS.

To get another form, you can simply use

$form = array(); // new form
$defaults = drupal_get_form('my_default_form_builder_function');
$form += $defaults; // add defaults to new form
1
  • I do not think the drupal_http_request function is useful for me in that context since I have to send the user to the provided url. Unless I'm wrong drupal_http_request doesn't do so? I'm gonna look into the drupal_get_form tho!
    – Ebpo
    Commented Jan 9, 2013 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.