By pederbennedsen on
After years of programming in ASP.NET i am now learning Drupal. What a great experience :-) I'm amazed..!
But it is a challenge to learn how to do some of the low-level stuff i'm used to.
I have a Drupal Webform where the user can enter an amount in Euro.
On the change event of that field another field should be updated with the same amount exchanged to USD.
I know how to do this in ASP.NET with a jQuery call to a page/webservice on my server that talks to Google Finance or the like.
But I have not been able to find any example of how this is done easily in Drupal.
Here is code for the server-side call to Google Finance: http://www.expertcore.org/viewtopic.php?f=67&t=2161
Comments
Jquery
Jquery is Javascript. http://drupal.org/node/304255
Thx. Any hints for the
Thx.
Any hints for the backend-file/webservice?
Is it possible to create a "plain PHP-file" for this purpose?
Please Elaborate
Hi,
Can you please elaborate.
In your original post you specified that all of the logic was performed with javascript. Do you mean javascript running in the user's browser makes a request to the google service? "yelvington" posted a link to the Drupal javascript integration documents and you replied that you want help with "backend-file/webservice" and "plain PHP-file"?
Can you layout your sequence calls, For example:
How do you plan on making the request to google? From the user's web browser, with javascript? Or do you post the user's input to the Drupal server and want Drupal to make the request to google.
Maybe you can post the sequence you used with asp.net?
Once you specify the sequence, then you can detail where in the process you need help.
Also, are you using Drupal's form api https://drupal.org/node/751826 ? or are you referring to the contributed module "Web Form"?
It always helps if you post the relevant part of your code (that you need help with),
Hope that helps:)
Good Luck
Hi, When the user leaves the
Hi,
When the user leaves the amount-field, jQuery calls a PHP-page on my server.
The PHP-file calls Google and returns the result to jQuery (which handles it asynchronously).
The form should not be submitted.
I want the Drupal server to make the request to Google to avoid "cross-domain scripting".
I have the javascript/jQuery running so I only need to create a PHP-file that calls Google and returns the result.
So the question right now is: How do I create a "page"/PHP-file in Drupal, that doesn't return a full-blown page with menus, graphics and everything, just the result, preferably as JSON..?
Refer to "Examples for Developers"
Hi,
Thank you for the response.
I would refer to "Examples for Developers' located here https://drupal.org/project/examples
Specifically, the "ajax_example".
You can also peruse some of the example code online. http://api.drupal.org/api/examples/ajax_example!ajax_example.module/group/ajax_example/7.
To find the others online, just go to the main Drupal API page http://api.drupal.org/api/drupal, type "Example" in the search box, the site will auto-complete a list of examples. You might also want to review the form example. Drupal needs to create a cached copy of your form so that it can verify the requester.
Use drupal_http_request() to make a request from Drupal to google. Details here: http://api.drupal.org/api/drupal/includes!common.inc/function/drupal_http_request/7
.
You'll also need to house your code in a "module", Here's a guide : https://drupal.org/node/361112. You'll need to install and enable your module.
Hope that helps :)
Good Luck