So I've been using in-line (correct term?) ColdFusion code to run all my pages and have gotten to a point where I think I have a decent understanding of the basics, and want to take the next step. After a lot of cross-referencing, research, and trial and error, I've come up with the following 4 pages of which the intent is to be able to enter a username and password in the form page (crud.cfm), then, after submission, redirect the user to a page which displays the newly entered data, as well as any past entries.
I can do all of this with simple in-line code and an Application.CFM but I want to migrate toward a more OOP/Modular approach going forward, as presently I find myself rewriting/copy-pasting scads of code across several different pages. The error that I get when I submit from 'crud.cfm' is:
"The component attribute in cfinvoke tag has invalid value."
I have tried it without hashes and without the uppercase "A" to no avail. Here is my non-working code:
Application.cfc
<cfcomponent output="false"> <cffunction name="insertrecord" access="public" output="false"> <cfargument name="data" type="struct" required="true"> <cfquery name="create" datasource="test"> INSERT INTO logins( username, password) VALUES( 'trim(form.username)', 'trim(form.password)') </cfquery> </cffunction> </cfcomponent> crud.cfm
<h3> Enter new user/password </h3> <cfform name="thisform" method="post" action="procpage.cfm"> Username:<cfinput type="text" name="username" value=""> Password:<cfinput type="password" name="password" value=""> <input type="submit" value="submit"> </cfform> procpage.cfm
<cfif !StructIsEmpty(form)> <cfinvoke component="#Application#" method="insertrecord"> <cfinvokeargument name="data" value="#form#"> </cfinvoke> </cfif> <cflocation url="resultpage.cfm" addtoken="no"> resultpage.cfm
<cfquery name="read" datasource="test"> SELECT * FROM logins </cfquery> <table> <tr> <th>LOGIN</th> <th>USERNAME</th> <th>PASSWORD</th> </tr> <cfloop query="read"> <tr> <td>#read.login#</td> <td>#read.username#</td> <td>#read.password#</td> </tr> </cfloop> </table> ColdFusion version 8, MSSQL 2005 database. Thank you all in advance for your help, looking forward to your responses!
cfinvokecall.Applicationalso happens to be a reserved word in ColdFusion for the Application scope. Just create a new .cfc file with your function in it and call that instead.