Closed andrelecomte closed 9 years ago
Not really sure what you're asking -- do you mean you just want to send one field rather than a nested construct? If so, it does not, but I could help you figure out how to do that instead.
What is the ResponseType
?
Sorry, if you could help me figure it out that would be great!
I do just want to send the nested XML construct as a value for one field. Could I somehow use a hook or modify forms-3rdparty-integration.php
or forms-3rdparty-xpost.php
so this is added to the start of the POST body?: ResponseType=StatusCode&XMLString=
XMLString
is the form field where the 3rd-party service expects to receive all the XML data. ResponseType
is another form field that allows a choice between either a "Status Code Response" or an "XML Response" from the submission URL. Is it possible to POST one field (ie., XMLString
) that contains all the form submission data?
Currently the raw body of my POST starts like this:
%3C%3Fxml+version=%221.0%22
However, I think it needs these static parameters added at the start:
ResponseType=StatusCode&XMLString=%3C%3Fxml+version%3D%221.0%22
You could hook to ..._service_filter_args
to change the $args['body']
to what you're looking for. Just make sure to hook later than Xpost (>12) does so the output will already have been transformed.
Sorry, I don't understand php. Something like this?: $args[ResponseType=StatusCode&XMLString='body']
no, more like:
$args['body'] = http_build_query(array(
'ResponseType' => 'StatusCode',
'XMLString' => $args['body']
));
Thank you very much! Am I on the right track by adding this to my theme's functions.php
?:
add_filter('Forms3rdPartyIntegration_service_filter_args', 'MY_HOOK', 10, 3);
function MY_HOOK ($args) {
$args['body'] = http_build_query(array(
'ResponseType' => 'StatusCode',
'XMLString' => $args['body']
));}
yes -- but the 3
of ...'MY_HOOK', 10, 3);
means your hook function expects 3 arguments, so it should look more like:
function MY_HOOK($args, $service, $form)
like Xpost: https://github.com/zaus/forms-3rdparty-xpost/blob/master/forms-3rdparty-xpost.php#L42
Since you only need the first param $args
, you can change the hook to 1, but for the sake of conformity (i.e. so you don't later forget you have the other stuff available) you might want to add the other arguments.
I added $service
and $form
; thanks for the explanation!
Now I've got stuck with the output being empty. Could this be an issue with hook priority?:
Warning: Invalid argument supplied for foreach() in wp-content/plugins/forms-3rd-party-xpost/forms-3rdparty-xpost.php on line 126
Warning: array_merge() [function.array-merge]: Argument #2 is not an array in wp-content/plugins/forms-3rd-party-xpost/forms-3rdparty-xpost.php on line 143
Ah... My mistake. I forgot to mention that you need to set a later priority than xpost - so the 10 in "10, 3" should be more like 13 (bigger than xpost's 12) in order to allow it to turn the body into XML before you manipulate it further. Also, are you returning $args at the end of your hook? That might be why you got the null warning. WP filters are mean to transform and return the first argument (as opposed to actions that don't return anything).
Thanks for the tips! I tried this in functions.php
:
add_filter( 'Forms3rdPartyIntegration_service_filter_args', 'MY_HOOK', 13, 3 );
function MY_HOOK( $service, $form, $args ) {
$args['body'] = http_build_query(array(
'ResponseType' => 'StatusCode',
'XMLString' => $args['body']
));
... but the only way I could get it to work was by changing line 84 in forms-3rdparty-xpost.php
to this:
$args['body'] = http_build_query(array( 'ResponseType' => 'StatusCode', 'XMLString' => $this->simple_xmlify($args['body'], null, isset($root) ? $root : 'post')->asXML() ));
Your solution just forgot to return $args
at the end -- then it would have worked. No need to change the plugin source.
Also, the order of your hook arguments are wrong. As in, it should look like:
add_filter( 'Forms3rdPartyIntegration_service_filter_args', 'MY_HOOK', 13, 3 );
function MY_HOOK( $args, $service, $form ) {
$args['body'] = http_build_query(array(
'ResponseType' => 'StatusCode',
'XMLString' => $args['body']
));
return $args; // you forgot this line too
}
This works perfectly. Thanks for all your help!!
I love these plugins and was happy to find the XML nesting feature. Thank you for your great development!!
Is it possible to post parameters like this?:
XMLString: <?xml version="1.0" encoding="UTF-8"?><name>John</name>
ResponseType: StatusCode