zaus / forms-3rdparty-xpost

Converts external submission from [Forms: 3rdparty Integration](http://wordpress.org/plugins/forms-3rdparty-integration/) plugin to XML post; optionally can add custom headers (to allow SOAP submissions).
4 stars 2 forks source link

Need some guidance on XML #8

Closed OllieJames closed 9 years ago

OllieJames commented 9 years ago

Hi @zaus ,

First Thank You for all your work on this plugin. I'm trying to post to an xml service url using 3rd Party Integration and Xpost plugins. Do I need to map the form values and the post string? or just the url string for the xml? And where is the xml post string, I only see the place to enter XML root elements.

Thank You.

zaus commented 9 years ago

This plugin just turns the form post (field1=value1&field2=value2) from Forms 3rdparty Integration into XML (<field1>value1</field1><field2>value2</field2>), with optional nesting, root element, and headers.

You still need to configure the service mapping to get the fields.

zaus commented 9 years ago

Let me know how I can make this more clear from the plugin description. Or submit a pull request with readme changes ;)

OllieJames commented 9 years ago

Thank You for your reply. I'll look over the readme again to see how it can be clearer.

In the meantime how would I add the header of

<?xml version="1.0" encoding="UTF-8"?>

Thanks again.

OllieJames commented 9 years ago

darn it it cut the other code out. Attached is a screenshot xmlheader

OllieJames commented 9 years ago

@zaus,

Can I send you my xml file and a screenshot of my set up for assistance. I will gladly pay you for your help. I will also help you create screenshots of the set up to add to the readme which I think should help clarify usage. Thank You. My email is oliver@realizemarketing.com

zaus commented 9 years ago

Hey, getting back to you via email.

Regarding xml attributes, you would normally be able to include them by prefixing the field name with @, but since this is for the root "wrapper" it might be a little trickier. Could you try setting the very first mapping in the table to a 'static value' with key=@xmlns and value=http://www.lowermy...? Then the rest of the fields would need to be prefixed with LmbLead, rather than using it as part of the nested wrapper.

zaus commented 9 years ago

Looks like I can generate the important parts of the XML with the following configuration (import service using Forms 3rdparty Migration with "merged" checkbox selected, and (re)attach to appropriate form/change mappings):

{
    "999": {
        "name": "LmbLeads Sample",
        "url": "/wp-content/plugins/forms-3rdparty-integration/3rd-parties/service_test.php",
        "forms": [
            "cf7_93"
        ],
        "success": "",
        "failure": "",
        "timeout": "",
        "hook": "true",
        "as-xpost": "true",
        "xpost-wrapper": "LmbLeads",
        "xpost-header": "",
        "mapping": [
            {
                "val": "1",
                "lbl": "xmlnamespace",
                "src": "http://www.lowermybills.com/hla/2006",
                "3rd": "@xmlns"
            },
            {
                "lbl": "",
                "src": "FirstName",
                "3rd": "LmbLead/FirstName"
            },
            {
                "lbl": "",
                "src": "LastName",
                "3rd": "LmbLead/LastName"
            },
            {
                "lbl": "",
                "src": "Email",
                "3rd": "LmbLead/Email"
            },
            {
                "lbl": "",
                "src": "SSN",
                "3rd": "LmbLead/SSN"
            },
            {
                "lbl": "",
                "src": "MaritalStatus",
                "3rd": "LmbLead/MaritalStatus"
            },
            {
                "lbl": "",
                "src": "B2_FirstName",
                "3rd": "LmbLead/B2_FirstName"
            }
        ]
    }
}

which results in the following being sent:

<?xml version="1.0"?>
<LmbLeads xmlns="http://www.lowermybills.com/hla/2006">
    <LmbLead>
        <FirstName>MyFirst</FirstName>
        <LastName>MyLast</LastName>
        <Email>MyEmail@email.com</Email>
        <SSN>111-22-3333</SSN>
        <MaritalStatus>Married</MaritalStatus>
        <B2_FirstName>Penelope</B2_FirstName>
    </LmbLead>
</LmbLeads>
zaus commented 9 years ago

And it turns out you can "trick" the plugin into adding extra prolog attributes just by adding almost the whole declaration to the root element input, like ?xml version="1.0" encoding="UTF-8"?><LmbLeads rather than just LmbLeads.

This works because SimpleXMLElement is fairly flexible with parsing its root element -- see http://stackoverflow.com/questions/5992268/simplexml-how-to-correctly-set-encoding-and-xmins -- and all the plugin is doing is wrapping the provided root value.

mdkaufman commented 9 years ago

Hey @zaus,

I'm trying to accomplish something similar as @OllieJames and having issues with the XML root elements. I'm trying to wrap the xml data created by the form in the following:


<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <SOAP-ENV:Body>
        <m:SubmitQuote xmlns:m="http://tempuri.org/">
            <m:authenticationKey>1234-5678-1233</m:authenticationKey>
            <m:payLoad>
                             <![CDATA[<ACORD>***XML DATA***</ACORD>]]>
                        </m:payLoad>
        </m:SubmitQuote>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Thank you for all of your great work on these plugins. Any help would be greatly appreciated and I'd be happy to compensate you for your help.

zaus commented 8 years ago

@mdkaufman I recently ran into an issue on a client where the prolog wasn't getting parsed (maybe newer/older version of PHP? I gave up...)

Anyway, I added a 'mask' option to the plugin so you can specify the body template and element templates instead, which may help you with the complex XML.

luisdiazvenero commented 7 years ago

hello @mdkaufman, i'm trying something similar like yours, how did you resolve it?

hi @zaus nice work! i'm trying to use the "mask option" but i can't get it done, could you please publish some example for this? thanks.