getting a custom attribute from the current item in ColdFusion? - coldfusion

Disclaimer, I'm a ColdFusion newbie...
I'm using Mura CMS 6, and I've got a question with regards to accessing a custom attribute.
My contentRenderer.cfc file has code for a Bootstrap Carousel. I'd like to be able to output the contents of a custom attribute on the file that the carousel is using, but I'm not entirely sure how to do that.
My custom attribute is named 'imageLink', but I have no idea how to get the current context to be able to output the contents of this attribute to the screen.
The following code is the code for the carousel (I didn't write it)
<cfsavecontent variable="local.str"><cfoutput>
<!--- BEGIN: Bootstrap Carousel --->
<!--- IMPORTANT: This will only output items that have associated images --->
<cfset local.feed = variables.$.getBean('feed').loadBy(name=arguments.feedName)>
<cfset local.iterator = local.feed.getIterator()>
<cfif local.feed.getIsNew()>
<div class="container">
<div class="alert alert-info alert-block">
<button type="button" class="close" data-dismiss="alert"><i class="fa fa-remove"></i></button>
<h4>Ooops!</h4>
The <strong>#HTMLEditFormat(arguments.feedName)#</strong> Content Collection/Local Index does not exist.
</div>
</div>
<cfelseif local.iterator.hasNext()>
<div id="#arguments.cssID#" class="carousel slide" data-interval="#arguments.interval#">
<!--- Indicators --->
<cfif arguments.showIndicators>
<ol class="carousel-indicators">
<cfset local.iterator.reset()>
<cfset local.idx = 0>
<cfloop condition="local.iterator.hasNext()">
<cfset local.item=iterator.next()>
<cfif ListFindNoCase('jpg,jpeg,gif,png', ListLast(local.item.getImageURL(), '.'))>
<li data-target="###arguments.cssID#" data-slide-to="#idx#" class="<cfif local.idx eq 0>active</cfif>"></li>
<cfset local.idx++>
</cfif>
</cfloop>
</ol>
</cfif>
<!--- Wrapper for slides --->
<div class="carousel-inner" role="listbox">
<cfset local.iterator.reset()>
<cfset local.idx = 0>
<cfloop condition="local.iterator.hasNext()">
<cfset local.item=iterator.next()>
<cfif ListFindNoCase('jpg,jpeg,gif,png', ListLast(local.item.getImageURL(), '.'))>
<div class="item<cfif local.idx eq 0> active</cfif>">
<img src="#local.item.getImageURL(argumentCollection=local.imageArgs)#" alt="#HTMLEditFormat(local.item.getTitle())#">
<cfif arguments.showCaption>
<div class="container">
<div class="carousel-caption">
<h2>#HTMLEditFormat(local.item.getTitle())#</h2>
#local.item.getTitle()#
<!-- <p><a class="btn btn-larg btn-primary" href="#local.item.getURL()#">Read More</a></p>-->
</div>
</div>
</cfif>
</div>
<cfset local.idx++>
</cfif>
</cfloop>
</div>
<cfif local.idx>
<!--- Controls --->
<cfif local.idx gt 1>
<a class="left carousel-control" href="###arguments.cssID#" data-slide="prev" role="button">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="###arguments.cssID#" data-slide="next" role="button">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
<!--- AutoStart --->
<cfif arguments.autoStart>
<script>jQuery(document).ready(function($){$('###arguments.cssID#').carousel({interval:#arguments.interval#});});</script>
</cfif>
</cfif>
<cfelse>
<div class="alert alert-info alert-block">
<button type="button" class="close" data-dismiss="alert"><i class="fa fa-remove"></i></button>
<h4>Oh snap!</h4>
Your feed has no items <em>with images</em>.
</div>
</cfif>
</div>
<cfelse>
<div class="alert alert-info alert-block">
<button type="button" class="close" data-dismiss="alert"><i class="fa fa-remove"></i></button>
<h4>Heads up!</h4>
Your feed has no items.
</div>
</cfif>
<!--- // END: Bootstrap Carousel --->
</cfoutput></cfsavecontent>
How can I access the current context to output that attribute?

Here are the docs on how to display them.
http://docs.getmura.com/v6/back-end/class-extension-manager/displaying-extended-attributes/
It looks like you looping through a collection of content so I believe this would work.
#local.item.get("imageLink")#

Assuming you are working within the cfloop and after the line
<cfset local.item=iterator.next()>
You can get your custom imageLink value using
#local.item.getImageLink()#
or
#local.item.getValue('imageLink')#

Related

Creating highlighted results in Coldfusion

I have output from a table that I want highlighted should a certain requirement not be met. I have it working fine for one section, but then when I use the code on a QofQ after an inner join of two tables, it doesn't work.
I can see when I dump the variables that they are correct and I know 100% that one of the companies contains no negative data so should display correctly but both companies are displaying in red.
I'm obviously not seeing something or does QofQ have limitations that are causing this ?
I'm still learning so please be kind :)
Queries :
<cfquery name="suppNeg" datasource="users">
SELECT companies.subID, companies.companyID, companies.suppName
, suppresult_old.companyID, suppresult_old.O18, suppresult_old.O19
, suppresult_old.O20, suppresult_old.O22, suppresult_old.WDPVC1
, suppresult_old.WDPVC2, quarterID
FROM suppresult_old INNER JOIN companies
ON suppresult_old.companyID=companies.companyID
WHERE quarterID = 8
AND companies.subID = #session.auth.companyID#
ORDER BY companies.suppName ASC
</cfquery>
<cfquery dbtype="query" name="subs">
SELECT DISTINCT suppName, companyID, subID
FROM suppNeg
ORDER BY suppName ASC
</cfquery>
<cfquery name="columntotals" datasource="users">
SELECT O18,O19,O20,O22, WDPVC1, WDPVC2
FROM suppresult_old INNER JOIN companies
ON suppresult_old.companyID=companies.companyID
WHERE quarterID = 8
AND companies.subID = #session.auth.companyID#
</cfquery>
<cfset O18Value = valueList(columntotals.O18) />
<cfset O18total = listToArray(O18Value) />
<cfset O19Value = valueList(columntotals.O19) />
<cfset O19total = listToArray(O19Value) />
<cfset O20Value = valueList(columntotals.O20) />
<cfset O20total = listToArray(O20Value) />
<cfset O22Value = valueList(columntotals.O22) />
<cfset O22total = listToArray(O22Value) />
<cfset WDPVC1Value = valueList(columntotals.WDPVC1) />
<cfset WDPVC1total = listToArray(WDPVC1Value) />
<cfset WDPVC2Value = valueList(columntotals.WDPVC2) />
<cfset WDPVC2total = listToArray(WDPVC2Value) />
<cfquery name="suppliers" datasource="users">
SELECT suppName, companyID, subID
FROM companies
WHERE subID=#session.auth.companyID#
ORDER BY suppName ASC
</cfquery>
Output :
<cfoutput query="subs">
<div class="container" width="1100">
<div class="row">
<a href="2tierReport.cfm?quarterID=8&companyID=#companyID#">
<cfif (arraysum(O18total)) LT 0>
<div class ="col-sm-4 supphighlight1">
<h4>
<span class="glyphicon glyphicon-exclamation-sign" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong></a>
</h4>
</div>
</a>
<a href="2tierReport.cfm?quarterID=8&companyID=#companyID#">
<cfelseif (arraysum(O19total)) LT 0>
<div class ="col-sm-4 supphighlight1">
<h4>
<span class="glyphicon glyphicon-exclamation-sign" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong>
</h4>
</div>
</a>
<a href="2tierReport.cfm?quarterID=8&companyID=#companyID#">
<cfelseif (arraysum(O20total)) LT 0>
<div class ="col-sm-4 supphighlight1">
<h4>
<span class="glyphicon glyphicon-exclamation-sign" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong>
</h4>
</div>
</a>
<a href="2tierReport.cfm?quarterID=8&companyID=#companyID#">
<cfelseif (arraysum(O22total)) lt 0>
<div class ="col-sm-4 supphighlight1">
<h4>
<span class="glyphicon glyphicon-exclamation-sign" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong>
</h4>
</div>
</a>
<a href="2tierReport.cfm?quarterID=8&companyID=#companyID#">
<cfelseif (arraysum(WDPVC1total)) LT 0>
<div class ="col-sm-4 supphighlight1">
<h4>
<span class="glyphicon glyphicon-exclamation-sign" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong>
</h4>
</div>
</a>
<a href="2tierReport.cfm?quarterID=8&companyID=#companyID#">
<cfelseif (arraysum(WDPVC2total)) LT 0>
<div class ="col-sm-4 supphighlight1">
<h4>
<span class="glyphicon glyphicon-exclamation-sign" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong>
</h4>
</div>
</a>
<cfelse>
<a href="suppReports_admin.cfm?quarterID=8&companyID=#companyID#">
<div class ="col-sm-4 supphighlight">
<h4>
<span class="glyphicon glyphicon-ok-circle" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong>
</h4>
</div>
</a>
....
That's a lot to digest, without any data samples, but I'll take a stab at it :) I think the problem is that the code is comparing apples and oranges. The "sub" query contains the details for individual companies and subId's. (I've no idea what the real data looks like, so the samples below are just for illustration)
However, the cfif comparisons calculate the overall total for all companies and subId's. So if the overall total for O20 (O18, etc..) is negative, then it'll be negative for every company in the cfoutput.
Runnable TryCF.com Example
If all you want is the totals, by companyId and subId, it's much easier to calculate that in SQL. Instead of all the ValueList(), ArraySum() and QoQ's, use the SQL aggregate function SUM(). I don't know which DBMS you're using, but something like this should work in most any database:
Note: I "guessed" that quarterID is a column in the suppresult_old table
<!--- NOT TESTED --->
<cfquery name="totalsByCompany" datasource="users">
SELECT companies.subID
, companies.companyID
, companies.suppName
, suppresult_old.quarterID
, SUM(suppresult_old.O18) AS O18Total
, SUM(suppresult_old.O19) AS O19Total
, SUM(suppresult_old.O20) AS O20Total
, SUM(suppresult_old.O22) AS O22Total
, SUM(suppresult_old.WDPVC1) AS WDPVC1Total
, SUM(suppresult_old.WDPVC2) AS WDPVC2Total
FROM suppresult_old
INNER JOIN companies ON suppresult_old.companyID=companies.companyID
WHERE suppresult_old.quarterID = 8
AND companies.subID= <cfqueryparam value="#session.auth.companyID#" cfsqltype="cf_sql_integer">
GROUP BY companies.subID
, companies.companyID
, companies.suppName
, suppresult_old.quarterID
ORDER BY companies.suppName ASC
</cfquery>
Then in your cfoutput, use the calculated SUM's:
<cfoutput query="totalsByCompany">
....
<cfif O18total LT 0> .... code here
<cfelseif O19total LT 0>.... code here
<cfelse> ...
</cfif>
</cfoutput>
Aside: If you're new to S.O., might want to take a gander at How to create a Minimal, Complete, and Verifiable example. Putting together (the smallest possible) self-contained example demonstrating the problem makes it a LOT easier for others to assist, and less likely the question will be closed as too broad :) Also, tools like https://trycf.com and https://sqlfiddle.com are great for sharing runnable examples.

fine uploader w/ cold-fusion upload the scaled images in different folder

Hey guys i am stuck at a point .I have a situation where i need to upload the scaled image in different folder for example :- 1(small).jpg on small folder , 1(medium).jpg on medium folder and 1.jpg on uploads folder. Right now the code below is uploading all 3 images on different folders but the files are blob files.How to get the scaled image . (edited the code)
<cfset destinationDirectory = expandpath('/file_uploader/uploads')>
<cfset counter = 1>
<cfset uniqueFileName = "">
<cfset destinationFilePath = "">
<cfset smallfile = "">
<cfset mediumfile ="">
<cfset mainfile= ''>
<cfscript>
variables.validMimeTypes = {'image/jpeg': {extension: 'jpg'}
,'image/png': {extension: 'png'}
,'image/png': {extension: 'gif'}
}; </cfscript>
<cftry>
<cfset cnt= 1>
<cfset file_name = #qqfilename#>
<cfset file_size = #qqtotalfilesize#>
<!--- If a file with the same name already exists at the destination --->
<cfif fileExists(destinationDirectory & "/" & file_name)>
<!--- Loop up to 100 times to try create a unique file_name --->
<cfset destinationFilePath = destinationDirectory & "/" & counter & "_" & file_name>
<!--- Loop up to 100 times to try create a unique filename --->
<cfloop condition="counter LT 100">
<cfset destinationFilePath = destinationDirectory & "/" & counter & "_" & file_name>
<cfif fileExists(destinationFilePath)>
<cfset counter++>
<cfelse>
<cfset uniqueFileName = "IMG" & counter & "_" & file_name>
<cfbreak/>
</cfif>
</cfloop>
<!--- Filename does not already exist at the destination --->
<cfelse>
<cfset uniqueFileName = "IMG" & "_" & file_name>
<cfset destinationFilePath = destinationDirectory & "/" & file_name>
</cfif>
<cfif len(trim(uniqueFileName))>
<cfset session.cntr ++>
<cfif find("(small)",file_name) neq 0>
<cfset smallfile = file_name>
<cffile
action="upload"
destination="#UploadPath2#"
accept="#StructKeyList(variables.validMimeTypes)#"
nameconflict="#smallfile#"
>
<cfelseif find("(medium)",file_name) neq 0>
<cfset mediumfile = file_name>
<cffile
action="upload"
filefield="qqfile"
destination="#UploadPath1#"
accept="#StructKeyList(variables.validMimeTypes)#"
nameconflict="#uniqueFileName#"
>
<cfelse>
<cfset mainfile= file_name>
<cffile
action="upload"
filefield="qqfile"
destination="#destinationFilePath#"
accept="#StructKeyList(variables.validMimeTypes)#"
nameconflict="#uniqueFileName#"
>
</cfif>
<CFSET local.response['success'] = true >
<CFSET local.response['type'] = 'xhr' >
<CFSET local.response['obj'] = session.cntr >
<cfelse>
<CFSET local.response['error'] = 'Unable to move the file and create a unique file_name at the destination'>
</cfif>
<cfoutput>
#serializeJSON(local.response,true)#
</cfoutput>
<cfabort/>
<cfcatch type="any">
<cfoutput> #serializeJSON(session.cntr,true)# </cfoutput>
<cfabort/>
</cfcatch> </cftry>
below is the UI page
<!DOCTYPE html> <html> <head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- jQuery
====================================================================== -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!-- Fine Uploader Gallery CSS file
====================================================================== -->
<link href="../file_uploader/includes/fine-uploader-gallery.css" rel="stylesheet">
<!-- Fine Uploader JS file
====================================================================== -->
<script src="../file_uploader/includes/all.fine-uploader.js"></script>
<script src="../file_uploader/includes/all.fine-uploader.min.js"></script>
<script src="../file_uploader/includes/jquery.fine-uploader.js"></script>
<script src="../file_uploader/includes/jquery.fine-uploader.min.js"></script>
<!-- Fine Uploader Gallery template
====================================================================== -->
<script type="text/template" id="qq-template-gallery">
<div class="qq-uploader-selector qq-uploader qq-gallery" qq-drop-area-text="Drop files here">
<div class="qq-total-progress-bar-container-selector qq-total-progress-bar-container">
<div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" class="qq-total-progress-bar-selector qq-progress-bar qq-total-progress-bar"></div>
</div>
<div class="qq-upload-drop-area-selector qq-upload-drop-area" qq-hide-dropzone>
<span class="qq-upload-drop-area-text-selector"></span>
</div>
<div class="qq-upload-button-selector qq-upload-button">
<div>Upload a file </div>
</div>
<span class="qq-drop-processing-selector qq-drop-processing">
<span>Processing dropped files...</span>
<span class="qq-drop-processing-spinner-selector qq-drop-processing-spinner"></span>
</span>
<ul class="qq-upload-list-selector qq-upload-list" role="region" aria-live="polite" aria-relevant="additions removals">
<li>
<span role="status" class="qq-upload-status-text-selector qq-upload-status-text"></span>
<div class="qq-progress-bar-container-selector qq-progress-bar-container">
<div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" class="qq-progress-bar-selector qq-progress-bar"></div>
</div>
<span class="qq-upload-spinner-selector qq-upload-spinner"></span>
<div class="qq-thumbnail-wrapper">
<img class="qq-thumbnail-selector" qq-max-size="120" qq-server-scale>
</div>
<button type="button" class="qq-upload-cancel-selector qq-upload-cancel">X</button>
<button type="button" class="qq-upload-retry-selector qq-upload-retry">
<span class="qq-btn qq-retry-icon" aria-label="Retry"></span>
Retry
</button>
<div class="qq-file-info">
<div class="qq-file-name">
<span class="qq-upload-file-selector qq-upload-file"></span>
<span class="qq-edit-filename-icon-selector qq-edit-filename-icon" aria-label="Edit filename"></span>
</div>
<input class="qq-edit-filename-selector qq-edit-filename" tabindex="0" type="text">
<span class="qq-upload-size-selector qq-upload-size"></span>
<button type="button" class="qq-btn qq-upload-delete-selector qq-upload-delete">
<span class="qq-btn qq-delete-icon" aria-label="Delete"></span>
</button>
<button type="button" class="qq-btn qq-upload-pause-selector qq-upload-pause">
<span class="qq-btn qq-pause-icon" aria-label="Pause"></span>
</button>
<button type="button" class="qq-btn qq-upload-continue-selector qq-upload-continue">
<span class="qq-btn qq-continue-icon" aria-label="Continue"></span>
</button>
</div>
</li>
</ul>
<dialog class="qq-alert-dialog-selector">
<div class="qq-dialog-message-selector"></div>
<div class="qq-dialog-buttons">
<button type="button" class="qq-cancel-button-selector">Close</button>
</div>
</dialog>
<dialog class="qq-confirm-dialog-selector">
<div class="qq-dialog-message-selector"></div>
<div class="qq-dialog-buttons">
<button type="button" class="qq-cancel-button-selector">No</button>
<button type="button" class="qq-ok-button-selector">Yes</button>
</div>
</dialog>
<dialog class="qq-prompt-dialog-selector">
<div class="qq-dialog-message-selector"></div>
<input type="text">
<div class="qq-dialog-buttons">
<button type="button" class="qq-cancel-button-selector">Cancel</button>
<button type="button" class="qq-ok-button-selector">Ok</button>
</div>
</dialog>
</div>
</script>
<title>Fine Uploader Gallery View Demo</title> </head> <body>
<!-- Fine Uploader DOM Element
====================================================================== -->
<div id="fine-uploader-gallery"></div>
<!-- Your code to create an instance of Fine Uploader and bind to the DOM/template
====================================================================== -->
<script> var posturl = "../file_uploader/upload_file.cfm"; var t= 0;
var galleryUploader = new qq.FineUploader({
element: document.getElementById("fine-uploader-gallery"),
//debug: true,
autoUpload: false,
template: 'qq-template-gallery',
request:
{
// endpoint: '../file_uploader/upload_file.cfm?id=<cfoutput>#session.cntr#</cfoutput>'
endpoint: posturl
},
thumbnails:
{
placeholders:
{
waitingPath: '../file_uploader/includes/placeholders/waiting-generic.png',
notAvailablePath: '../file_uploader/includes/placeholders/not_available-generic.png'
}
},
validation:
{
allowedExtensions: ['jpeg', 'jpg', 'gif', 'png']
},
callbacks: {
onComplete: function(id, name, responseJSON , xhrOrXdr)
{
if (responseJSON.success)
{
t++;
alert("success"+t);
uploadSuccess: {
endpoint: "../file_uploader/upload_file.cfm?id=1"
}
}
},
onError: function(id, name, errorReason, xhrOrXdr)
{
alert(qq.format("Error on file number {} - {}. Reason: {}", id, name, errorReason));
}
},
scaling:
{
//hideScaled: true,
sizes:
[
{name: "small", maxSize: 100},
{name: "medium", maxSize: 300}
]
}
});
</script> </body> </html>
There are at least two ways to determine the scaled size of an image. One way would be to look for the appropriate prefix in the image's file name. For example, if you've instructed Fine Uploader to include the phrase "small", then you should look for the string "(small)" in the file name server-side. The same goes for any other size prefix you have specified in your scaling options.
Another option would be to look at the actual size of the files in a scaling group. Each scaled file in a group will contain a qqparentuuid request parameter pointing to the UUID of the original image/file. Once you have all of these files, you can examine their sizes to determine which one is small, medium, large, etc.
I highly suggest using the first option.

Form counting every record when clicking submit?

I have a form that im outputting results of comments, it can more than one.
I can aprrove these comments all at once, but what I'm trying to do is make it
with the option to submit 1 comment at a time or all comments at a time.
The form at first I wrote it to work on 'submit all', so now with adding a submit
per comment also, I get some errors.
I get because every time I submit a comment (1 comment) its still looking for all the other comments
which I did not submit.
What I think is doing since txtTotalRecords= Mush2.Recordcount, it trying to find the
other records which weren't submitted.
I just can't figure out how I can change this to make it work.
Doing a cfdump on the form i get, meaning there are 11 comments to submit.
How would I be able to change RecordCount to take in every record by itself?
<cfparam name="FormSubmit" type="string" default="FormNotSubmitted">
<cfif isDefined("form.submit")><cfset FormSubmit = "FormSubmitted"></cfif>
<cfif isDefined("form.submit1")><cfset FormSubmit = "FormSubmitted1"></cfif>
<!--- Begin Content ================================================== --->
<cfif FormSubmit eq "FormNotSubmitted" || FormSubmit eq "FormNotSubmitted1" >
<form method="post" action="cse_execoffice_pending.cfm" name="review_comments">
<cfoutput>
<input type="hidden" name="txtApprovedBy" value="#GetCurrentUser.emp_id#">
<!-- count the records that come in from the pending -->
</cfoutput>
<cfoutput query="Mush3">
<form method="post" action="cse_execoffice_pending.cfm" name="review_onecomment">
<input type="hidden" name="txtTotalRecords" value="#Mush2.Recordcount#">
<hr>
<div class="comments_approvaldecision">
<p>
<CFDUMP VAR=#response_id#>
<input type="hidden" name="txtResponseID#mush2.CurrentRow#" value="#response_id#">
<input type="radio" name="execoffice_status#mush2.CurrentRow#" id="approve#CurrentRow#" value="1" checked="checked"> <label for="approve#CurrentRow#">Approve</label><br>
<input type="radio" name="execoffice_status#mush2.CurrentRow#" id="deny#CurrentRow#" value="2"> <label for="deny#CurrentRow#">Deny</label>
</p>
<p> </p>
<p>
<input type="radio" name="star#mush2.CurrentRow#" id="givestar#mush2.CurrentRow#" value="0" checked="checked"> <label for="givestar#CurrentRow#"></i> Give Star!</label><br>
<input type="radio" name="star#mush2.CurrentRow#" id="denystar#mush2.CurrentRow#" value="1"> <label for="denystar#CurrentRow#"></i> No Star</label>
</p>
</div>
</div>
<input type="submit" name="Submit1" value="Submit">
</form>
</cfoutput>
<p><input type="submit" name="Submit" value="Submit"></p>
</form>
</cfif>
<cfdump var="#form#">
<cfif FormSubmit eq "FormSubmitted" || FormSubmit eq "FormSubmitted1">
<!--- Get Form Values --->
<cfloop from="1" to="#txtTotalRecords#" index="j">
<h2>test</h2>
<cfset response_id[j] = #Trim(form["txtResponseID" & j])#>
<cfset execoffice_status[j] = #Trim(form["execoffice_status" & j])#>
<cfset star[j] = #Trim(form["star" & j])#>
<cfset commentpositive[j] = #Trim(form["txtCommentPositive" & j])#>
<cfset commentnegative[j] = #Trim(form["txtCommentNegative" & j])#>
<cfset commentpositivereReplace[j] = reReplace(commentpositive[j], '\n', '<br>', 'ALL')>
<cfset commentnegativereReplace[j] = reReplace(commentnegative[j], '\n', '<br>', 'ALL')>
</cfloop>
......... more code...
I believe the code you are getting errors on is not in your sample code listed on this page.
I'm assuming you are doing a to/from loop based upon form.txtTotalRecords.
What you'll want to do is loop over your form items looking for a specific partial form name.
something like this:
<cfloop list="form.fieldnames" index="i">
<cfif left(i,13) IS "txtResponseID">
<cfset thisID = replaceNoCase(i,"txtResponseID","")>
<cfquery>
UPDATE myTable
SET approve = <cfqueryparam value="#form["execoffice_status" & thisID]#">
WHERE ID = <cfqueryparam value="#thisID">
</cfquery>
</cfif>
</cfloop>

File Upload is executing multiple times

I am trying to create a form where by the user selects a location where they then upload a document using CFFILE ACTION ="UPLOAD". I am not great at this so any help you could provide would be greatly appreciated.
Below is my code. Essentially, there is a dropdown list of folder locations. The user first selects one of the locations. Then clicks 'browse' to choose a file. Finally they click submit and the file uploads.
The code that is #dir# is the folder location that is linked to each of the location names. What is happening at the moment is that the document gets uploaded successfully... but it is uploading to all the folder locations instead of the one that is selected from the dropdown. Here is my code:
docuploads.cfm
<cfquery name="getLocation">
SELECT *
FROM Locations
ORDER BY FolderName
</cfquery>
<form action="docuploads.cfm" method="POST" enctype="multipart/form-data" name="upload_form" id="upload_form">
<select name="folderID">
<option value="">--- Select Folder ---</option>
<cfoutput query="getLocation">
<option value="#FolderName#"">#FolderName#</option>
</cfoutput>
</select>
<cfoutput query="getLocation">
<CFIF IsDefined("form.upload_now")>
<CFIF structKeyExists(form, "ul_path") and len(form["ul_path"])>
<CFFILE ACTION="UPLOAD" FILEFIELD="ul_path"
DESTINATION="C:\Documents\#dir#\"
NAMECONFLICT="OverWrite">
<CFSET ClientFilePath = "#clientDirectory#\#clientFile#">
</CFIF>
</CFIF>
</CFOUTPUT>
<br /><br />
Click on the Browse button to select the file to Upload:<br>
<input type="file" name="ul_path" id="ul_path" style="height: 22px;width: 350px;" value=""><br><br>
<input type="submit" name="upload_now" id="upload_now" value="Submit" style="height: 22px;">
<input type="button" name="clear" value="Clear" style="height: 22px;">
<br /><br /><br />
</form>
I hope this makes some sense - can anyone shed any light on getting this to work?
I am assuming that you didnt post the complete code because your #clientDirectory#/#clientFile# don't seem to have a source in your code above.
I put together a possible sample of what It may look like. I also moved your upload routine from the body of your code to the top for readability.
<CFIF IsDefined("form.upload_now")>
<CFIF structKeyExists(form, "ul_path") and len(form["ul_path"])>
<!--- assuming you need to lookup info from the database --->
<cfquery name="getThisLocation">
SELECT FolderID, FolderName, dir
FROM Locations
where foldername=#form.folderid#
</cfquery>
<CFFILE ACTION="UPLOAD" FILEFIELD="ul_path"
DESTINATION="C:\Documents\#getThisLocation.dir#\"
NAMECONFLICT="OverWrite">
<CFSET ClientFilePath = "#getThisLocation.clientDirectory#\##getThisLocation.clientFile#">
</CFIF>
</CFIF>
<cfquery name="getLocation">
SELECT *
FROM Locations
ORDER BY FolderName
</cfquery>
<form action="docuploads.cfm" method="POST" enctype="multipart/form-data" name="upload_form" id="upload_form">
<CFIF IsDefined("form.upload_now")>
<CFIF structKeyExists(form, "ul_path") and len(form["ul_path"])>
<P>FILE UPLOADED</P>
</CFIF>
</CFIF>
<select name="folderID">
<option value="">--- Select Folder ---</option>
<cfoutput query="getLocation">
<option value="#FolderName#"">#FolderName#</option>
</cfoutput>
</select>
<br /><br />
Click on the Browse button to select the file to Upload:<br>
<input type="file" name="ul_path" id="ul_path" style="height: 22px;width: 350px;" value=""><br><br>
<input type="submit" name="upload_now" id="upload_now" value="Submit" style="height: 22px;">
<input type="button" name="clear" value="Clear" style="height: 22px;">
<br /><br /><br />
</form>
I also added a snippet of code to let the user know that the file has been uploaded.
Please try this:
<CFIF IsDefined("form.upload_now")>
<CFIF structKeyExists(form, "ul_path") and len(form["ul_path"])>
<CFFILE ACTION="UPLOAD" FILEFIELD="#form.ul_path#"
DESTINATION="C:\Documents\#dir#\"
NAMECONFLICT="OverWrite">
<CFSET ClientFilePath = "#clientDirectory#\#clientFile#">
</CFIF>
<cfoutput>file uploaded successfully</cfoutput>
</CFIF>
<cfquery name="getLocation">
SELECT *
FROM Locations
ORDER BY FolderName
</cfquery>
<form action="docuploads.cfm" method="POST" enctype="multipart/form-data" name="upload_form" id="upload_form">
<select name="folderID">
<option value="">--- Select Folder ---</option>
<cfoutput query="getLocation">
<option value="#FolderName#"">#FolderName#</option>
</cfoutput>
</select>
<br /><br />
Click on the Browse button to select the file to Upload:<br>
<input type="file" name="ul_path" id="ul_path" style="height: 22px;width: 350px;" value=""><br><br>
<input type="submit" name="upload_now" id="upload_now" value="Submit" style="height: 22px;">
<input type="button" name="clear" value="Clear" style="height: 22px;">
<br /><br /><br />

checkbox on page load in coldfusion

I have 2 check boxes like below on a coldfusion form. On page load I want both to be checked
and display a query result depending on which checkbox is checked. I have the below code working fine except for the scernario where I uncheck both the checkboxes and hit view now. As im setting
form.chkbox=""
on page load they are remaining checked even after I uncheck them. How can i make them remain unchecked upon page load. I tried using the JS function, but it doesnt seem to work
<script type="text/javascript">
function callme(){
var box1 = document.getElementById('chkbox1').checked;
var box2 = document.getElementById('chkbox2').checked;
if (box1 && box2){
alert("checked") ;
}else{
box1.checked = false;
box2.checked = false;
}
}
</script>
<cfset form.chkbox="">
<form action="view_emp_qual.cfm?show=yes" method="post" name="Myform">
<table align="center">
<tr>
<td>
<cfif isDefined("form.chkbox") and (form.chkbox eq "" or listfind(form.chkbox, 1))>
<input type="checkbox" checked="checked" name="chkbox" id="chkbox1" value="1">
<cfelse>
<input type="checkbox" name="chkbox" id="chkbox1" value="1">
<input type="hidden" name="chkbox" id="chkbox1" value="1">
</cfif>
<strong> Agreement Only</strong>
<cfif isDefineD("form.chkbox") and (form.chkbox eq "" or listfind(form.chkbox, 2))>
<input type="checkbox" checked="checked" name="chkbox" id="chkbox2" value="2">
<cfelse>
<input type="checkbox" name="chkbox" id="chkbox2" value="2">
<input type="hidden" name="chkbox" id="chkbox2" value="2">
</cfif>
<strong>Active Employees</strong>
</td>
<td><input type="Submit" name="submitnow" value="View Selected" class="button" onclick="return callme();"> </td>
</tr>
</table>
</form>
<cfif not isDefined("form.chkbox")>
Query1
<cfelseif isDefined("form.chkbox") and ( listfind(form.chkbox, 1) eq 0 and listfind(form.chkbox, 2) eq 1)>
Query 2
<cfelseif isDefineD("form.chkbox") and (listfind(form.chkbox, 1) eq 1 and listfind(form.chkbox, 2) eq 0)>
query 3
<cfelse>
query4
</cfif>
If you are submitting the form in same page then following code may solve your purpose.
I have made some adjustment with your main code. Please have a look.
<cfdump var="#form#" label="before">
<!---flag for checking if form has submitted or not--->
<cfif Not isDefined("form.submitnow")>
<cfset form.chkbox = "1,2">
</cfif>
<cfdump var="#form#" label="after">
<cfif isDefined("form.chkbox") >
<cfdump var="#listfind(form.chkbox, 1)#" ><br>
<cfdump var="#listfind(form.chkbox, 2)#" >
</cfif>
<form action="" method="post" name="Myform">
<table align="center">
<tr>
<td>
<!---I have removed hidden fields and made a few changes in conditional checking --->
<cfif isDefined("form.chkbox") and (listfind(form.chkbox, 1))>
<input type="checkbox" checked="checked" name="chkbox" id="chkbox1" value="1"><span>1</span>
<cfelse>
<input type="checkbox" name="chkbox" id="chkbox1" value="1"><span>2</span>
</cfif>
<strong> Agreement Only</strong>
<cfif isDefineD("form.chkbox") and (listfind(form.chkbox, 2))>
<input type="checkbox" checked="checked" name="chkbox" id="chkbox2" value="2"><span>3</span>
<cfelse>
<input type="checkbox" name="chkbox" id="chkbox2" value="2"><span>4</span>
</cfif>
<strong>Active Employees</strong>
</td>
<td>
<input type="Submit" name="submitnow" value="View Selected" class="button">
</td>
</tr>
</table>
</form>
<cfif not isDefined("form.chkbox")>
Query1
<cfelseif isDefined("form.chkbox") and ( listfind(form.chkbox, 1) eq 0 and listfind(form.chkbox, 2) eq 1)>
Query 2
<cfelseif isDefineD("form.chkbox") and (listfind(form.chkbox, 1) eq 1 and listfind(form.chkbox, 2) eq 0)>
query 3
<cfelse>
query4
</cfif>