1 Replies - 6766 Views - Last Post: 06 August 2012 - 06:44 AM Rate Topic: -----

#1 De.camm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-March 12

confuse of <cfinvoke> function

Posted 24 July 2012 - 08:11 PM

Hi there, I need help on understanding of function <cfinvoke> in coldfusion,
is it anyway to insert data into database without using <cfquery..>[INSERT INTO..]],
Is it possible to using <cfinvoke> in inserting data into database??

Another problem I had is, I try to edit some code which is had <cfinvoke> wording, then some
related data I remove intended to edit the code, but why error come out with the data I already remove ??
really wonder of this thing happen.

here I attach the code and the error appear.

<h2>Add New User</h2>
<br />

<!--- Get rank --->
<cfquery name="qUserRanking" datasource="#Variables.Fw.Config.DSN#">
	SELECT * FROM USERTYPE
	WHERE utype_name = '#Variables.fw.User.type#'
</cfquery>

<cfset rank = qUserRanking.utype_rank>

<!---Initialize--->
<cfparam name="dept" default="0">
<cfparam name="position" default="0">
<cfparam name="dir" default="">
<cfparam name="NAME" default="">
<cfparam name="form.office" default="0">
<cfparam name="Form.tit" default="">
<cfparam name="Form.dir" default="">
<cfparam name="Form.department" default="">

<!--- Check if form is submitted, perform validation if it is --->
<cfif isDefined ("Form.adduser")>
	
	<cfset errors = "0">
    
    <cfif Form.department EQ "">
		<cfset errors = "1">
			<cfscript>
                fw_ErrorMsg("Section name missing. Press <a href=javascript:history.back()>back</a> and select section name.");
            </cfscript>
		<cfreturn>
	</cfif>
    
    <cfif Form.username EQ "" OR Form.fullname EQ "">
		<cfset errors = "1">
		<cfscript>
			fw_ErrorMsg("Login name missing. Press <a href=javascript:history.back()>back</a> and fill in your desired login name.");
		</cfscript>
		<cfreturn>
	</cfif>
    
    <!--- See if username already exist --->
    <cfquery name="qValidUsername" datasource="#Application.fw.Config.DSN#">
		SELECT user_id FROM Users 
        WHERE user_login = <cfqueryparam value = "#Form.username#" cfsqltype = "cf_sql_char">
	</cfquery>
    
    <cfif qValidUsername.RecordCount>
		<cfset errors = "1">
		<cfscript>
			Application.fw_ErrorMsg("Login name already exist. Press <a href=javascript:history.back()>back</a> and choose another login name.");
		</cfscript>
		<cfreturn>
	</cfif>
    
    <cfquery name="qValidEmail" datasource="#Application.fw.Config.DSN#">
		SELECT user_id FROM Users 
        WHERE user_email = <cfqueryparam value = "#Form.email#" cfsqltype = "cf_sql_char">
	</cfquery>
    
    <cfif qValidEmail.RecordCount>
		<cfset errors = "1">
			<cfscript>
                Application.fw_ErrorMsg("Email already exist. Press <a href=javascript:history.back()>back</a> and choose another email.");
            </cfscript>
		<cfreturn>
	</cfif>
    
    <!--- Check if email is valid --->
    <cfif email EQ "">
    	<cfset error = "1">
        <cfscript>
			Application.fw_ErrorMsg("A valid email Address is required.Press<a href=javascript:history.back()>back</a> and fill in a valid email address.");
		</cfscript>
	</cfif>
    
    <!--- Check if both password is the same and long enough --->
    <cfif Compare(Form.password,Form.password2) EQ "0" AND Len(Trim(Form.password)) GTE "5" AND Len(Trim(Form.password2)) GTE "5">
	<cfelse>
		<cfset errors = "1">
		<cfscript>
			Application.fw_ErrorMsg("Password is case-sensitive and must be at least 5 characters long. Press <a href=javascript:history.back()>back</a> and choose another password.");
		</cfscript>
		<cfreturn>
	</cfif>
    
    <cfif errors EQ "0">
    <cfinvoke component="#fw.Config.AppDir#.users.user" method="addUser"
    	fname="#form.fullname#"
        user="#form.username#"
        pass="#form.password#"
        pass2="#form.password2#"
        email="#form.email#"
        group="#form.office#"
        department="form.department"
        tit="#form.tit#"
        position="#form.position#"
        dir="#Form.dir#"
        suspend="#Form.suspend#"
        tel="#Form.telephone#"
        barcodeid="#form.barcode_id#"
        returnvariable="check"
        >
    </cfif>
    
    <cfscript>
		Variables.fw_Notice("Staff '#form.FULLNAME#' created.");
	</cfscript>
    <cfreturn>
</cfif>

<cfquery name="qTitle" datasource="#Variables.fw.config.DSN#">
    SELECT * FROM TITLE 
    ORDER BY TITLE_NAME_BI
</cfquery>

<cfquery name="qOffice" datasource="#Application.fw.Config.DSN#">
    SELECT DISTINCT(brgrp_office) AS office_id from deptgrp WHERE brgrp_deptid='#form.office#'
</cfquery>

<cfquery name="qPosition" datasource="#Variables.fw.Config.DSN#">
	SELECT * FROM POSITION
	ORDER BY POS_NAME_ENG ASC
</cfquery>

<cfquery name="qDepartment" datasource="#Variables.fw.Config.DSN#">
	SELECT * FROM DEPARTMENT_U 
    ORDER BY dept_name_eng asc
</cfquery>

<script>
function validate(){
	if (document.getElementById('department').value == "") { alert('Section cannot be empty!') ; return false;}
	if (document.getElementById('fullname').value == "") { alert('Fullname empty!') ; return false;}
	if (document.getElementById('email').value == "") { alert('Email empty!') ; return false;}
	if (document.getElementById('username').value == "") { alert('User ID empty!') ; return false;}
	if (document.getElementById('password').value == "") { alert('Password empty!') ; return false;}
	return true;
	}
</script>

<form action="index.cfm?section=users" method="POST" enctype="multipart/form-data">
<input type="hidden" name="section" value="users">
<input type="hidden" name="action" value="add">
<table width="100%" class="news_frame" cellspacing="2" cellpadding="5">
	<tr>
    	<td align="center" class="news_title">
        	<table class="form">
            	<tr>
                	<td>Section</td>
                    <td>:</td>
                    <td>
                    <cfoutput>
                    	<select name="department" id="department">
                            		 <option value="" >-- Choose One --</option>
                             <cfloop query="qDepartment">
                             <option value="#qDepartment.dept_id#" <cfif qDepartment.dept_id EQ dept>selected</cfif>>#qDepartment.dept_name_eng# 
                                 | #qDepartment.dept_name_mal#</option>
                             </cfloop>
                        </select>
                    </cfoutput>
                    </td>
                </tr>
                <tr> 
            		<td>Office</td>
            		<td>:</td>
                    <td>
                    <cfoutput>
                    <select name="office">
                    	<option value="">-- Choose One--</option>
                        <cfloop query="qOffice">
                        	<option value="#qOffice.office_id#">
                            <cfif 
		  						#qOffice.office_id# EQ "" or #qOffice.office_id# EQ 0>None
		  					<cfelse>
          						#fw_Check_table(qOffice.office_id,"office_id","office","office_name")#
		  					</cfif>
                            </option>
                        </cfloop>
                     </select>#fw_Check_table(qOffice.office_id,"office_id","office","office_name")#
                     </cfoutput>
                    </td>
				</tr>
                <tr> 
                    <td>Position</td>
                    <td>:</td>
                    <td> 
						<cfoutput> 
                		<select name="position">
                        		<option value="" >-- Choose One --</option>
                  			<cfloop query="qPosition">
                    			<option value="#qPosition.pos_id#" <cfif qPosition.pos_id EQ position>selected</cfif>>#qPosition.pos_name_eng# 
                    			| #qPosition.pos_name_mal#</option>
                  			</cfloop>
                		</select>
              			</cfoutput>
                    </td>
          		</tr> 
                <tr><td colspan="3"><hr/></td></tr>
                <tr>
                	<td>Title</td>
                    <td>:</td>
                    <td>
                    	<select name="tit">
                        	<option value="0">-------- Select -------</Option>
			  				<cfoutput query="qTitle">
			  					<option value="#qTitle.title_id#"
									<cfif Form.tit EQ qTitle.title_id>
									selected
									</cfif>
									>#qTitle.title_name_bi# | #qTitle.title_name_bm#</option>
			  				</cfoutput>
              			</select>
                    </td>
                </tr>
                <tr>
                	<td>Name</td>
                    <td>:</td>
                    <td><input type="text" name="fullname" size="50" maxlength="50" /></td>
                </tr>
                <tr>
                	<td>Telephone</td>
                    <td>:</td>
                    <td><input type="text" name="telephone" size="20" maxlength="50" /> </td>
                </tr>
                <tr>
                	<td>Fax</td>
                    <td>:</td>
                    <td><input type="text" name="fax" size="20" maxlength="50" /></td>
                </tr>
                <tr>
                	<td>Email Address</td>
                    <td>:</td>
                    <td><input type="text" name="email" size="20" maxlength="50" /></td>
                </tr>
                <tr><td colspan="3"><hr /></td></tr>
                <tr>
                	<td>User ID</td>
                    <td>:</td>
                    <td><input type="text" name="username" size="20" maxlength="20" /></td>
                </tr>
                <tr>
               		<td>User Barcode ID</td>
                    <td>:</td>
                    <td><input  type="text" name="barcode_id" id="barcode_id"
                    	onkeypress="if(event.keyCode ==13){}; return event.keyCode!=13;" maxlength="10" />
                    </td>
                </tr>
                <tr>
                	<td>Password</td>
                    <td>:</td>
                    <td><input type="password" name="password" size="20" maxlength="20" /></td>
                </tr>
                <tr>
                	<td>Confirm Password</td>
                    <td>:</td>
                    <td><input type="password" name="password2" size="20" maxlength="20" /></td>
                </tr>
                <tr>	
                	<td>User Photo</td>
                    <td>:</td>
                    <td>
                    	<input type="file" name="image" style="width:300px;" />
                        <font size="1">(Auto resize: 150x200)</font>
                    </td>
                </tr>
                <tr>
                	<td valign="top">System Access</td>
                    <td valign="top">:</td>
                    <td valign="top">
                    	<script language="Javascript">   
							function expand(getIt){  
							 checkbox = "s"+ getIt;
							document.getElementById(checkbox).style.display=(document.getElementById(checkbox).style.display=="none")?"":"none";  
							}    
						</script>
                        <cfquery name="qGroup" datasource="#Variables.fw.Config.DSN#">
                            SELECT * FROM system
                            WHERE status = 1
                    	</cfquery> 
                        <cfif qGroup.recordcount NEQ 0>
                        	<table>
								<cfset i=0>
                                <cfoutput query="qGroup">
                                <cfif #system_name# NEQ "KBS" <!---AND #system_name# NEQ "Homepage"--->>
                                <cfset i+=1>
                                <cfif i mod 2>
                        		<tr><td>
									<cfelse>
                            		<td>
                            		</cfif>
                                       <input name="G#qGroup.system_id#" 
                                       id="G#qGroup.system_id#" 
                                       type="checkbox" 
                                       value="#qGroup.system_id#" 
                                       onclick="expand('#qGroup.system_id#')"/> 
                                       #qGroup.system_name#
                            		</td>
                                    <td>
                                    <select id="s#qGroup.system_id#" name="s#qGroup.system_id#" style="display:none;">
                                    <option value="">--Select One--</option>
                                            <cfquery name="qSysGroup" datasource="#Variables.fw.Config.DSN#">
                                                SELECT * FROM systems_access
                                                WHERE status = 1 and system_id='#qGroup.system_id#'
                                            </cfquery> 
                                            <cfloop query="qSysGroup">
                                            <option value="#qSysGroup.group_id#">#fw_Check_table(qSysGroup.group_id,"group_id","groups","group_name")#</option>
                                            </cfloop>
                                    </select>
                                    </td>
								<cfif i mod 2>
                                <cfelse>
                        		</td></tr>
                        		</cfif></cfif>
                        		</cfoutput>
                    		</table>
                        </cfif>
                    </td>
                </tr>
                <tr><td colspan="3"><hr /></td></tr>
                <tr>
                	<td>Display in Directory</td>
                    <td>:</td>
                    <td>
                    	<cfif #session.user_group# EQ "SuperAdmin">
                        <select name="dir" id="dir">
                        	<option value="Yes">Yes</option>
                            <option value="No">No</option>
                        </select>
                        <cfelse>
                        <select name="dir" id="dir">
                        	<option value="No">No</option>
                        </select>
                        </cfif>
                    </td>
                </tr>
                <tr>
                	<td>Suspend</td>
                    <td>:</td>
                    <td>
                    	<select name="suspend">
                        	<option value="No">No</option>
                            <option value="Yes">Yes</option>
                        </select>   
                    </td>
                </tr>
                <tr>
                	<td colspan="3" align="center">
                    	<br /><br />
                        <input type="submit" name="adduser" value="Create User" onclick="return validate();" />
                        <input type="reset" name="reset" value="Reset Form" />
                        <br /><br />
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
</form>

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: confuse of <cfinvoke> function

#2 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1926
  • View blog
  • Posts: 3,471
  • Joined: 13-January 08

Re: confuse of <cfinvoke> function

Posted 06 August 2012 - 06:44 AM

Quote

...is it anyway to insert data into database without using <cfquery..>[INSERT INTO..]]


You could call a stored procedure on the database that runs an insert statement with the data parameters you pass to the stored proc. Writing a stored procedure can be a little trickier than writing inline SQL in CF but it has several advantages if your application requires them. Stored procedures are done differently on different database applications so how to do so is kind of a separate subject (and one that can be answered in the MySQL or MS SQL forums.

Insofar as your error when trying to invoke the addUser method, you would need to go look at the addUser function in your user.cfc file. In there, you're likely to see a line that looks like this:
<cfargument name="DISTRICT" type="string" default="" required="true">

Since that line (or something similar) is there, it means that the function is expecting a parameter value for DISTRICT to be passed in. If you look at your code that starts at line 89, you're not passing that in so the function call errors and helpfully telling you that you're missing something it needs.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1