Jump to:

10987 Posts in 2724 Topics by 1817 members

All other Modules

SilverStripe Forums » All other Modules » UserForms - Need to Output Form Submissions as XML

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1225 Views
  • Garrett
    Avatar
    Community Member
    245 Posts

    UserForms - Need to Output Form Submissions as XML Link to this post

    Hi,

    I need to output the contents of the SubmittedFormField table as XML so that an external system can parse it. However, I don't seem to be able to write XML tags out in the template because I'm declaring the document type as XML:

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

    ...and the browser is seeing

    <% control OutputXML %>

    as malformed XML tags. I'm thinking there's probably some sort of built in method to do this in Silverstripe? I'll also need to customize the tags that go around the name/value pairs in the SubmittedFormField table. How do you output XML to the front end in SS?

    Thanks,
    Garrett

  • mi3ll
    Avatar
    Community Member
    24 Posts

    Re: UserForms - Need to Output Form Submissions as XML Link to this post

    I haven't worked with XML very much, but I think you should look at the Silverstripe Google Sitemaps module (comes with the default installation, or check it online here: https://github.com/silverstripe-labs/silverstripe-googlesitemaps)

    That module can give you a basic guide on how you can output XML on front end (sorry if its not much help...)

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: UserForms - Need to Output Form Submissions as XML Link to this post

    Yeah thanks but not really much help. @Willr, the main problem I am having is that each FIELD is a different record rather than each SUBMISSION being a different record. Regardless of whether I return it to the browser as a DataObjectSet somehow XML-ized or whether I return it as a string, there is no way for me to specify a new ID in the code each time I reach a new submission in the recordset. See below for example:

    I can do:

    <Id>1</Id>
    <First-Name>Garrett</First-Name>
    <Last-Name>Fisher</Last-Name>
    <Id>2</Id>
    <First-Name>Daniel</First-Name>
    <Last-Name>Geske</Last-Name>

    But what I need to do is:

    <form-result id="1">
    <First-Name>Garrett</First-Name>
    <Last-Name>Fisher</Last-Name>
    </form-result>
    <form-result id="2">
    <First-Name>Daniel</First-Name>
    <Last-Name>Geske</Last-Name>
    </form-result>

    @Willr -- How can I send these submission to the front end with each ParentID an individual record instead of each Field? How is this done in HTML in the the Reports tab in Userforms?

    Thanks,
    Garrett

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: UserForms - Need to Output Form Submissions as XML Link to this post

    @Willr, the main problem I am having is that each FIELD is a different record rather than each SUBMISSION

    Well yes, the module has to store each answer as it's own object since the number of submissions changes based on a form. If you want a unique ID for the XML then you can use the SubmittedForm ID. That will be unique and each field will have one.

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: UserForms - Need to Output Form Submissions as XML Link to this post

    Thanks @willr. Ok, I see now why you've modeled the data in this way - in order to turn it "on its side," as it were, you'd have to know how many fields the user added to the form. So I am getting my resultset like this:

    SELECT SFF.ParentID, SFF.Title, SFF.Value, EFF.XMLExportTagName AS TagName FROM SubmittedFormField SFF
    JOIN SubmittedForm SF ON SFF.ParentID = SF.ID
    JOIN EditableFormField EFF ON SFF.Name = EFF.Name
    ORDER BY SFF.ParentID ASC

    And I'll just have to shuffle them around in PHP. Thanks again for your help.

    1225 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.