coldfusion problem with flash form binding - coldfusion

i have the following :
<cfquery name="getArt" datasource="cfartgallery">
select * from art where artid < 10
</cfquery>
<cfform name="myform2" width="620" height="750" timeout="100" preservedata="yes" wmode="transparent">
<cfoutput query="getArt">
<cfinput id="pickers#currentRow#" name="pickmany" type="checkbox" value="#artname#" >
<label for="pickers#currentRow#">#artname#</label>
<br/>
</cfoutput>
<cfinput type="text" name="pickmany_selected" bind="{pickmany}" size="50">
</cfform>
whenever you check a box, it adds to the "pickmany_selected" field.
now, i am trying to do the same behaviour with a flash form.
<cfform name="myform" width="620" height="750" format="Flash" timeout="100" preservedata="yes" wmode="transparent">
<cfoutput query="getArt">
<cfinput id="pickers#currentRow#" name="pickmany" type="checkbox" value="#artname#" label="#artname#"><br/>
</cfoutput>
</cfform>
this breaks. it only works if i put name="pickmany#currentRow#":
<cfform name="myform" width="620" height="750" format="Flash" timeout="100" preservedata="yes" wmode="transparent">
<cfoutput query="getArt">
<cfinput id="pickers#currentRow#" name="pickmany#currentRow#" type="checkbox" value="#artname#" label="#artname#"><br/>
</cfoutput>
<cfinput type="text" name="pickmany_selected" bind="{pickmany1}" size="50">
</cfform>
what do i need to do for the flash form so that pickmany_selected binds correctly? in the last example, i cannot bind to a generic name. hate these flash forms.

it only works if i put
name="pickmany#currentRow#":
Yes, flash forms require all field names to be unique. Because of that, I suspect your goal is not possible with a bind. However, you could roll your own function and call it onClick. My flash skills are pretty rusty. But something along these lines:
<cfform name="myform" width="620" height="750" format="Flash" timeout="100" preservedata="yes" wmode="transparent">
<cfformitem type="script">
function updateSelectedArt():Void{
var elem;
var values = [];
var total = parseInt(myform.pickmany_total);
for (var i = 1; i <= total; i++) {
elem = _root["pickmany"+ i];
if (elem.selected) {
values.push(elem.label);
}
}
// use whatever delmiter makes sense
_root["pickmany_selected"].text = values.join(",");
}
</cfformitem>
<cfoutput query="getArt">
<cfinput name="pickmany#currentRow#" type="checkbox" value="#artname#" onClick="updateSelectedArt()" label="#artname#"><br/>
</cfoutput>
<cfinput type="hidden" name="pickmany_total" value="#getArt.recordCount#">
<cfinput type="text" name="pickmany_selected" value="" size="50">
</cfform>

Related

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>

Accessing variables of a dynamic form

I am creating a form with cfloop and need to access each variable individually when submitting the form. I need to use the selected entries of the form in a loop that will add my selections to a database.
This is my form:
<form method="post">
<input type="hidden" name="isPost" value="1">
...
<cfoutput>
<cfloop query="client_admin_surveys">
<input type="text" size="35" name="surveyID" id="surveyID" value="#id#">
<input type="text" size="35" name="surveyName" id="surveyName" value="#name#">
<input type="checkbox" name="amplify" id="amplify">
<input type="checkbox" name="enchance" id="enchance">
<input type="checkbox" name="pacify" id="pacify">
<input type="checkbox" name="pacifyUrgent" id="pacifyUrgent">
</cfloop>
</cfoutput>
...
<input type="submit" name="submit" value="Submit">
</form>
After posting the form, the results group all of my selections because I have the same "name" for my form elements. I tried adding an i count next to each name to make it different but then I got a bit confused about how to process the fields.
You started down the correct path when you added the counter - go back and add that, something like:
<input type="checkbox" name="amplify#client_admin_surveys.currentRow#" id="amplify">
Would work.
I also sometimes like to add a form field for the 'counter' on the processing page
<input type="hidden" name="counter" value="#client_admin_surveys.recordCount#" />
Then on the processing page, you can loop over the counter and access the form fields using bracket notation
<cfloop from="1" to="#form.counter#" indexd="i">
<cfset thisAmplify = form["amplify" & i] />
<cfset thisEnhance = form["enhance" & i] />
<!---- more logic here --->
</cfloop>

Where to put a cfquery in a Coldfusion Form

I have a cfquery that is using some of FORM fields in the WHERE clause. My first problem is that every time I access my webpage the cfquery code appears on the top of the page. Where should I put the query within the .cfm form and access some of the fields within the form? My second problem is I'm not sure that the WHERE clause is recognizing the values for the fields. Can you help me please?
Here is the way my code is set up:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="javascript" type="text/javascript">
function addRow() {
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
var iteration = lastRow - 3;
var row = tbl.insertRow(lastRow);
........... etcetra.......
}
</script>
</head>
<body lang=EN-US style='tab-interval:.5in'>
<div class=Section1>
<cfparam name="awardTotals" default="0" />
<cfparam name="search_award.GrandTotal" default="0" />
<cfif isDefined("form.Finalize")>
<cfquery name="search_award" datasource="Test">
SELECT g.Code1 + g.Code2 + g.Code3 + g.Code4 AS GrandTotal
FROM Codes g
WHERE g.CodeNumber = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.CodeNum#">
AND g.TestYear = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.TestYear#">
AND g.SelType = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.SelType#">
AND g.Jurisdiction = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.SelJuris#">
</cfquery>
<cfif not search_award.GrandTotal is FundingTotals>
<script type="text/javascript">
alert('The totals do not match.');
return false;
</script>
<cfelse>
<script type="text/javascript">
alert('The totals match.');
return true;
</script>
</cfif>
</cfif>
<p class=MsoNormal align=center style='text-align:center'><
<cfoutput>
<form name="thisform" action="FormData.cfm" method="post">
<p class=MsoNormal align=left style='text-align:left'>
<input type="hidden" id="totalFields" name="totalFields" value="0">
<input type="text" id="awardTotals" name="#search_award.GrantTotal#" value="0">
<table width="1177" border="1" id="tblSample">
<tr style='mso-yfti-irow:0;mso-yfti-firstrow:yes'>
<th height="10"bgcolor="##cccccc" colspan="10"><h3>Jurisdiction:
<select name="SelJuris" id="SelJuris">
<option value = "0">---Jurisdictions---</option>
<option value = "1">Allegany County</option>
<option value = "2">Anne Arundel County</option>
<option value = "3">Baltimore County</option>
<option value = "4">Calvert County</option>
<option value = "5">Caroline County</option>
</select>
<input name="CodeNum" id="CodeNum" type="text" size="20">
<input name="TestYear" id="TestYear" type="text" size="20">
<input name="SelType" id="SelType" type="text" size="20">
</th>
</tr>
</table>
<input type="Submit" name="Submit Form" value="Submit Form" onClick="">
<input type="Button" name="Finalize" value="Finalize" onClick="">
</form>
</body>
</cfoutput>
</html>
(Update from comments)
Right now I'm getting a message that Element CODENUM is undefined in FORM
You want this sort of logic. If the form has been submitted, do something with it. In your case, it would be like this:
<cfif structkeyexists(form, "codenum")>
query, process, display, etc
<cfif>
rest of page
Also, you want to use query parameters for a variety of reasons. So this:
g.CodeNumber = '#form.CodeNum#'
becomes this:
g.CodeNumber = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.CodeNum#">
unless it's a number in which case you change the datatype.
You need add a condition around your cfquery. Also update the name of your submit button without spaces
<input type="Submit" name="SubmitForm" value="Submit Form" onClick="">
<cfif isDefined("form.SubmitForm")>
<cfquery name="search_award" datasource="TrenaTest">
SELECT g.Code1 + g.Code2 + g.Code3 + g.Code4 AS GrandTotal
FROM Codes g
WHERE g.CodeNumber = '#form.CodeNum#'
AND g.TestYear = '#form.TestYear#'
AND g.SelType = '#form.SelType#'
AND g.JurisdictionID = '#form.SelJuris#'
</cfquery>
</cfif>
Please note that in all the examples, a standard html form tag is being used, but the condition for the query is defined in the Coldfusion form scope. I believe you would need to convert the <form> to <cfform> and <input> to <cfinput> like:
...........
<cfinput type="Submit" name="SubmitForm" value="Submit Form" onClick="">
</cfform>
<cfif isdefined('form.submit')>
.............

How to get checked value by cfloop in coldfusion

How can I get the checked values from some checkboxes using cfloop in coldfusion?
The checkboxes are created dynamically from a database query. ie:
<cfloop query="GetDataMaterial">
<input type="checkbox" name="MaterialID" value="#MaterialID#" />
</cfloop>
The form field will contain a comma-separated list of all values that are checked with the same form name.
For instance:
<input type="checkbox" name="MaterialID" value="1">
<input type="checkbox" name="MaterialID" value="2">
<input type="checkbox" name="MaterialID" value="4">
<input type="checkbox" name="MaterialID" value="8">
<input type="checkbox" name="MaterialID" value="16">
<input type="checkbox" name="MaterialID" value="32">
If the user Checks all of them, you'll get, assuming your form does a post:
form.MaterialID: "1,2,4,8,16,32"
If the user checks the first and last, you'll get
form.MaterialID: "1,32"
So, if you want to loop over them, you can
<cfloop list="#form.MaterialId#">
...
</cfloop>
Don't forget to have index="i" and use it to loop through the list of checkbox
<cfloop list="#form.MaterialId#" index="i">
<cfoutput>#i#</cfoutput>
</cfloop>

Preserving input value of type="file" in ColdFusion on postback

I have a form in ColdFusion that initially has 5 input fields for file uploading. Should the user realize they have more than 5 files to upload in the process of attaching them, I would like the form to preserve the values when it submits itself for the change in # of fields.
Using the <cfform> tag with the preservedata="yes" attribute is supposed to accomplish this - but all I'm getting is a temp value stored in the input's value on resubmit that isn't displayed in the field nor works for a submission.
edit: Thanks for the great answers everyone, you all helped and were correct. I was able to implement Adam's suggested solution. Works great! Thanks!
function changeFieldCount() // javascript function for submit on input count change
{
var count = document.forms[0].numtotal.options[document.forms[0].numtotal.selectedIndex].value;
document.forms[0].action = "me.cfm?count=" + count;
document.forms[0].submit();
}
<cfparam name="url.count" default="5">
<cfform name="dispfiles" method="post" enctype="multipart/form-data" preservedata="yes">
<!--- looping for file input fields --->
<cfloop index="counter" from="1" to="#url.count#">
<cfinput type="file" name="file#counter#" size="50" maxlength="60"><br>
</cfloop>
<br>Number of Files to Attach:
<!--- looping for # of input selection--->
<cfselect name="numtotal">
<cfloop index="cnt" from="1" to="20" step="1">
<cfoutput>
<option value="#cnt#" <cfif #cnt# eq #url.count#>selected</cfif>>
#cnt#
</option>
</cfoutput>
</cfloop>
</cfselect>
<cfinput type="button" name="op-display" value="Display" onclick="changeFieldCount()">
<cfinput type="button" name="op-upload" value="Attach Files" onclick="submitfrm(this.form)">
<cfinput type="button" name="cancel" value=" Cancel " onclick="window.close()">
</cfform>
This is what I'm getting when I view source on the resulting submission:
<input name="file1" id="file1" type="file" value=".../cfusion.war/neotmp8858718543274653167.tmp" maxlength="60" size="50" /><br>
This is by design in all browsers for security reasons. There is no way you can insert the value for a file field.
To elaborate on #SpliFF's answer, what you need to do is dynamically create more file fields with JavaScript.
Here's an example that uses jQuery to make the JavaScript a little easier. I've also used a variable to track the number of file fields displayed so that they all have a unique number appended to their names, making it possible to loop over and uniquely identify them server-side.
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
//track the current number of file fields displayed
var numUploadFields = 5;
//attach an anonymous function to the button to add more fields
$(function(){
$("#add5").click(function(){
for (var i = 0; i < 5; i++){
numUploadFields += 1;
var newHTML = "<br/><input type='file' name='upload" +
numUploadFields + "' />";
$("#someSection").append(newHTML);
}
});
});
</script>
<form method="post" action="">
<div id="someSection">
<input type="file" name="upload1" /><br/>
<input type="file" name="upload2" /><br/>
<input type="file" name="upload3" /><br/>
<input type="file" name="upload4" /><br/>
<input type="file" name="upload5" />
</div>
<input type="button" id="add5" value="Add 5 more file fields" />
</form>
Build additional file inputs using JS DOM methods. Since you aren't leaving the page this is fast and nothing is lost.