简体   繁体   中英

How do I process a form using a CFC in ColdFusion 11?

I am currently creating an engine for a client to submit XML to our web site, and I would like to process the data to a CFC. In order to test this, I have set up a simple form in a regular CFM file, as such...

<!DOCTYPE html>
<html>
    <head>
        <title>Testing CFC processing</title>
    </head>
    <body>
        <cfsavecontent variable="variables.testxml">
            <?xml version="1.0" encoding="UTF-8"?>
            <xmlRequest><headers>data</headers><body><Notification><Result Success="1"/><participantID>[ID number]</participantID><transactionNumber>000</transactionNumber></Notification></body></xmlRequest>
        </cfsavecontent>
        <form method="post" action="[site url]/main.cfc?method=testData">
            <cfoutput>
                <textarea name="data" cols="150" rows="5">#variables.testxml#</textarea>
            </cfoutput>
            <br/>
            <input type="submit" name="submit" value="Process Test" />
        </form>
    </body>
</html>

In the main.cfc I have a method called testData which is set up as follows...

remote void function testData(data) {
    writeOutput(arguments.data);
}

This test is just to check to see if the method is receiving the data it is sent. When I run it, it does not error, but it also does not output the XML data from the form.

In case it is pertinent, I have the component declared as follows...

component  displayname="[name]" accessors="true" output="true"

I can't figure out why the CFC is not receiving the form data (or if it is, why it is not outputting the form data). Can anyone offer any assistance?

I found the answer. It turns out there is no problem with the code above. The problem was in the Application.cfc. I had a method onCFCRequest that didn't have any code in it. It was blocking the CFC from receiving the data. After removing the function from my Application.cfc the method was able to receive the data without issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM