Habb
Habb

Reputation: 21

Mura Display Form Data in a Page

I have some custom html code where i need to get the name and image an caption from the form i created in the mura backend, how can i do this, i searched everywhere in the google groups but nothing related found, i just need a start what to do and how to find the saved data and for cfoutput i think i need to do iterations

<cfset it = $.getBean('content').loadBy(title='myform')>
    <cfdump var="#it#">
    <cfif it.hasNext()>
  <ul>
    <cfloop condition="it.hasNext()">
      <cfset item = it.next()>
      <li>
        #esapiEncode('html', item.get('name'))#
      </li>
    </cfloop>
  </ul>

i need to get the form and display the data in ul > li format as above but it is gives me error on hasnext() is not defined, which somewhat does make sense, but i am not sure what i am missing here

Upvotes: 1

Views: 393

Answers (1)

Charles Robertson
Charles Robertson

Reputation: 1820

OK. I can confirm that this works, using MURA CMS 7.1 & form builder.

ContentID:

The important part is to reference the form by its 'ContentID', which you can find in the 'Form Builder -> Form -> Advanced' section.

Variable References:

Also you will need to change the references to 'formContentId' & 'wddxImageFieldName', respectively.

Set-up:

To test this, just place it into your repective Themes template, and make sure that you have made at least one form submission

Based on Steve Withington's code, at:

https://gist.githubusercontent.com/stevewithington/5963610/raw/4d8bca4675500075b0a5831db52ccc9b8bf0bf57/mura-form-results.cfm

<cfscript>
  rsData = QueryNew('');
  dcm = $.getBean('dataCollectionManager');
  formContentId = '856499BD-01E2-48C9-CD1A0430D859E81B';
  wddxImageFieldName = 'AVATAR_ATTACHMENT';
</cfscript>

<cfif !Len($.event('responseid'))>
  <!--- All Form Submission Results --->
  <cfscript>
      formBean = $.getBean('content').loadBy(contentID=formContentId);
      if ( !formBean.getIsNew() ) {
          currentFieldList = dcm.getCurrentFieldList(formBean.getContentID());
          data = {
              sortby = 'entered'
              ,sortdirection = 'desc'
              ,keywords = ''
              ,siteid = $.event('siteid')
              ,contentid = formBean.getContentID()
          };
          rsData = dcm.getData(data);
      }
  </cfscript>
  <cfif !rsData.recordcount>
    <h3>Sorry, either the form does not exist, or no records have been submitted yet.</h3>
  <cfelse>
    <table cellspacing="5" cellpadding="5" border="1">
      <!--- FieldNames --->
      <thead>
          <tr>
            <th>&nbsp;</th>
            <th>Date/Time Entered</th>
            <cfloop list="#currentFieldList#" index="fieldName">
              <th>#esapiEncode('html', fieldName)#</th>
            </cfloop>
          </tr>
      </thead>
      <!--- Actual Output --->
      <tbody>
        <cfloop query="rsData">
            <tr>
              <!--- Edit --->
              <td>
                  <a href="./?responseid=#responseid#">Edit</a>
              </td>
              <!--- The Date/Time Stamp --->
              <td>
                  #entered#
              </td>
              <!--- The Data --->
              <!--- Forms are stored as WDDX files ... so we need to unpack them --->
              <cfwddx action="wddx2cfml" input="#data#" output="record" />
              <cfloop list="#currentFieldList#" index="fieldName">
                <td>
                  <cfif StructKeyExists(record, fieldName)>
                    #record[fieldName]#
                    <cfif CompareNoCase(fieldName,wddxImageFieldName) EQ 0>
                      <img src="#$.getURLForImage(record[fieldName])#">
                    </cfif>
                  <cfelse>
                    &nbsp;
                  </cfif>
                </td>
              </cfloop>
            </tr>
        </cfloop>
      </tbody>
    </table>
  </cfif>
</cfif>

Upvotes: 1

Related Questions