Using the Forms API to post information to an external source
Hello all. For one of my clients, we have a long multistep form that we use to collect information for a user and enroll him / her in a course. One thing we would like to do is POST some information to an external API. Is it possible, using the FAPI, to POST data to an external source? I was going to user $form['#method'], however, that only allows internal paths. Worst case scenario, I could create a custom submit callback which POSTS the data over using CURL, but I am hoping to find a more elegant solution. Any suggestions? Thanks in advance, Brian
#method specifies the way the form is submitted (either POST or GET). You want to change [#action] to the URL you want. Of course doing that will remove any validation from the form in FAPI. You will have to do all the validation yourself. Jamie Holly http://www.intoxination.net http://www.hollyit.net Brian Vuyk wrote:
Hello all.
For one of my clients, we have a long multistep form that we use to collect information for a user and enroll him / her in a course. One thing we would like to do is POST some information to an external API.
Is it possible, using the FAPI, to POST data to an external source? I was going to user $form['#method'], however, that only allows internal paths.
Worst case scenario, I could create a custom submit callback which POSTS the data over using CURL, but I am hoping to find a more elegant solution.
Any suggestions?
Thanks in advance,
Brian
On Tue, Aug 25, 2009 at 10:38 AM, Jamie Holly<hovercrafter@earthlink.net> wrote:
#method specifies the way the form is submitted (either POST or GET). You want to change [#action] to the URL you want. Of course doing that will remove any validation from the form in FAPI. You will have to do all the validation yourself.
Good point. My response assumed the page it POSTS to will do the validation and present an error screen where the user can do something. Cheers, Greg -- Greg Knaddison | 303-800-5623 | http://growingventuresolutions.com Cracking Drupal - Learn to protect your Drupal site from hackers Now available from Wiley http://crackingdrupal.com
Greg Knaddison wrote:
On Tue, Aug 25, 2009 at 10:38 AM, Jamie Holly<hovercrafter@earthlink.net> wrote:
#method specifies the way the form is submitted (either POST or GET). You want to change [#action] to the URL you want. Of course doing that will remove any validation from the form in FAPI. You will have to do all the validation yourself.
Good point. My response assumed the page it POSTS to will do the validation and present an error screen where the user can do something.
Cheers, Greg
The external source is a Paypal API which does all the validation etc.
Oops - that was a typo. #action was indeed what I meant, however, it only allows internal Drupal paths, so I can't point to to anything outside. Brian Jamie Holly wrote:
#method specifies the way the form is submitted (either POST or GET). You want to change [#action] to the URL you want. Of course doing that will remove any validation from the form in FAPI. You will have to do all the validation yourself.
Jamie Holly http://www.intoxination.net http://www.hollyit.net
Brian Vuyk wrote:
Hello all.
For one of my clients, we have a long multistep form that we use to collect information for a user and enroll him / her in a course. One thing we would like to do is POST some information to an external API.
Is it possible, using the FAPI, to POST data to an external source? I was going to user $form['#method'], however, that only allows internal paths.
Worst case scenario, I could create a custom submit callback which POSTS the data over using CURL, but I am hoping to find a more elegant solution.
Any suggestions?
Thanks in advance,
Brian
If you specify it as a full url ie: $form['#action']='http://www.mysite.com/formhandler/'; It should work. I use the same thing on a site in D6 where videos uploaded are uploaded directly to our encoding server and it handles all the validations, etc. Jamie Holly http://www.intoxination.net http://www.hollyit.net Brian Vuyk wrote:
Oops - that was a typo. #action was indeed what I meant, however, it only allows internal Drupal paths, so I can't point to to anything outside.
Brian
Jamie Holly wrote:
#method specifies the way the form is submitted (either POST or GET). You want to change [#action] to the URL you want. Of course doing that will remove any validation from the form in FAPI. You will have to do all the validation yourself.
Jamie Holly http://www.intoxination.net http://www.hollyit.net
Brian Vuyk wrote:
Hello all.
For one of my clients, we have a long multistep form that we use to collect information for a user and enroll him / her in a course. One thing we would like to do is POST some information to an external API.
Is it possible, using the FAPI, to POST data to an external source? I was going to user $form['#method'], however, that only allows internal paths.
Worst case scenario, I could create a custom submit callback which POSTS the data over using CURL, but I am hoping to find a more elegant solution.
Any suggestions?
Thanks in advance,
Brian
On Tue, Aug 25, 2009 at 10:34 AM, Brian Vuyk<brian@brianvuyk.com> wrote:
For one of my clients, we have a long multistep form that we use to collect information for a user and enroll him / her in a course. One thing we would like to do is POST some information to an external API.
Is it possible, using the FAPI, to POST data to an external source? I was going to user $form['#method'], however, that only allows internal paths.
I don't think so.
Worst case scenario, I could create a custom submit callback which POSTS the data over using CURL, but I am hoping to find a more elegant solution.
Use drupal_http_request over CURL if you must http://api.drupal.org/api/function/drupal_http_request
Any suggestions?
I would just create it as a static HTML form. FAPI is helpful when: 1. You are doing form processing 100% in Drupal 2. You are building a form for a shared module and want to allow site specific modifications via hook_form_alter/theme functions We know 1 isn't true. And I assume this is a form that is only useful for the one specific client site... Cheers, Greg -- Greg Knaddison | 303-800-5623 | http://growingventuresolutions.com Cracking Drupal - Learn to protect your Drupal site from hackers Now available from Wiley http://crackingdrupal.com
participants (3)
-
Brian Vuyk -
Greg Knaddison -
Jamie Holly