When I set a form #action to reference a non-Drupal site that site complains about the posted data because form_id, form_token and form_build_id are being included in the input. Is there anyway to avoid that? If so, in what part of the form workflow do I attempt that?

Comments

vvanaparthy’s picture

Why don't you collect the form, filter it and then do Curl to the other form?

TMSA’s picture

I was going to try something like that but I am a little clueless about how all this works. If I "curl to the other form" that server produces and returns html in response to the post, doesn't it? How does that returned html then get displayed in the user's browser? For example, the simple paypal module has php code like:

>
 $url = simple_paypal_get_url();
  $ch = curl_init();

  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, simple_paypal_post($vars));

  ob_start();

  if (curl_exec($ch)) {
    $info = ob_get_contents();
    curl_close($ch);
    ob_end_clean();
// other stuff
}
<

I need the workflow to continue at the other server. How would $info get displayed by the browser?

vvanaparthy’s picture

I don't suppose you are dealing with API here that you need to see what is the return html or array as a matter of fact. If you are dealing with API may be better use xml rpc or SOAP to get returns and exceptions.

No matter what, create a new success page and after you finish the curling of your variables, check if the call was successful and then make a drupal_goto() to that success page that you defined in hook_menu.

Code that may help you to do this is: may be others have more insights in to this

if (curl_errno($ch)) {
		  //handle the error here
		  $message = 'post : curl_exec';
			$message .= $curl_err;
			$message .= $postArray['email'];
			//watchdog
		}
		curl_close($ch);
	}
TMSA’s picture

I found that you can unset undesirable parts of the form in the #pre_render. This seems to give me the behavior I want. Thanks for your replies, vvanaparthy...I think your mention of "filter" made me look at the form workflow diagram in a way that helped me better understand what was going on.

Interestingly, the research I did seemed to indicate that to try to get a browser to redirect via post is exceedingly difficult. Here are some of the links:

http://www.phpbuilder.com/board/archive/index.php/t-10207638.html

http://frontier.userland.com/discuss/msgReader$4370?mode=topic
(see Matt Neuburg's second comment on this thread)