开发者

Within Drupal, POST to a script and redirect the user to it

开发者 https://www.devze.com 2023-02-21 12:01 出处:网络
I\'m new to Drupal and dont know how t开发者_高级运维o use it properly yet. I\'m stuck on this part where I\'m displaying links which when the user clicks on, I need the code to POST certain informait

I'm new to Drupal and dont know how t开发者_高级运维o use it properly yet. I'm stuck on this part where I'm displaying links which when the user clicks on, I need the code to POST certain informaiton to that link and then redirect the user to that page.

  1. User clicks on a link: [Enter Other Site]
  2. System posts UserId, SecretPasswrod, etc to http://www.theotherside.com/handle.php
  3. The User's browse is redirected to handle.php (whiuch redirects him elsewhere as appropriate)

I know how to do this in php (by creating a form on the page and then submitting it), but not sure how to do this 'properly' in Drupal.


I think you're looking for how to do POST using PHP. I'm not familiar of any Drupal specific method, but this is how I'd do it:

  • Create a module with a menu hook of name, say, mymodule-enter-other-site
  • Define and create page callback function: in it, put the POST code you want using e.g. HTTP POST from PHP example -- You may also want to define additional settings for permissions etc
  • Make the link you want user to click to point to yourdomain.com/mymodule-enter-other-site
  • Activate your module and give it a go

Should everything work as intended, page callback function is executed when user visits the address and you can build the data and finally redirect the user.


You don't need to use the HTTP POST from PHP example, Drupal has it's own process fot that: http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_http_request/7


There are two ways to do it in Drupal

1) Use FORM API to create the form and then write your form submit code in form_submit function see http://drupal.org/node/751826

2) Use the webform module to create the form. see http://drupal.org/project/webform

0

精彩评论

暂无评论...
验证码 换一张
取 消