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>
Related
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>
For example:
How many item you want to select? 1 2 3 4
If 3 is selected then
loop from 1 to 3
do something
end loop
I want everything process in the same page. Can someone let me know what I need to do? I tried cfselect and radio buttons but no luck. Thank you.
I think you're over thinking the problem. The form will return the value of the selected radio button.
HTML:
<form method="post" action="">
<p>HOW MANY YOU WANT?!? YOU CHOOSE NOW!</p>
<input type="radio" name="varname" value="1" onclick="this.form.submit();">1
<input type="radio" name="varname" value="2" onclick="this.form.submit();">2
<input type="radio" name="varname" value="3" onclick="this.form.submit();">3
<input type="submit">
</form>
ColdFusion:
<cfif isDefined("form.varname") AND form.varname GT 0>
<cfloop index="i" from="1" to="#form.varname#" step="1">
<!--- Do Stuff --->
</cfloop>
</cfif>
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 />
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')>
.............
I'm looking to pass form values in a cfform to a PDF using cfpdfform. Here's my little test page that loops through 50 records to pull the first and last name. I'm trying to just pull those into the pdf fields. Currently it puts in all 50 of the first names into the firstname field and all of the lastnames into the lastname field of the pdf. I'm not married to the submit button, but what are better options?
In my final iteration of this I'll be pulling in about 100 fields.
--Form--
<cfform name="autopdf" method="POST" action="automated_pdf_submit.cfm" enctype="multipart/form-data">
<h1>Select a state to insert into a PDF form</h1>
<div class="center">
<select name="pdfselect" id="pdfselect">
<option value="" selected>--Select State--</option>
<option value="FROI_NY.pdf">New York</option>
<option value="FROI_PA.pdf">Pennsylvania</option>
</select>
<cfinput type="hidden" name="statevalidate" onValidate="yourFunction"
message="YOU MUST SELECT A STATE TO CONTINUE!">
</div>
<table align="center" style="width:400px">
<tr>
<th></th>
<th>First Name</th>
<th>Last Name</th>
<th>Export to PDF</th>
</tr>
<cfoutput>
<cfloop query="#qryPersons#" startrow="1" endrow="50" >
<tr class="#IIf(CurrentRow Mod 2, DE('rowOdd'), DE('rowEven'))#" onmouseover="this.className='rowHighlight'"
<cfif CurrentRow Mod 2>onmouseout="this.className='rowOdd'"
<cfelse>onmouseout="this.className='rowEven'"</cfif>>
<td>#qryPersons.CurrentRow#</td>
<td>#qryPersons.LastName#</td>
<input type="hidden" name="FirstName" value="#qryPersons.LastName#">
<td>#qryPersons.FirstName#</td>
<input type="hidden" name="LastName" value="#qryPersons.FirstName#">
<td style="width:50px"><input type="submit" value="Create PDF"</td>
</tr>
</cfloop>
</cfoutput>
</table>
</cfform>
--Action--
<cfpdfform action="populate" source="forms\#form.pdfselect#">
<cfpdfformparam name="FirstName" value="#form.FirstName#">
<cfpdfformparam name="LastName" value="#form.LastName#">
</cfpdfform>
Your form fields are all named FirstName and LastName you need to make those unique
<cfloop query="#qryPersons#" startrow="1" endrow="50" >
<tr class="#IIf(CurrentRow Mod 2, DE('rowOdd'), DE('rowEven'))#" onmouseover="this.className='rowHighlight'"
<cfif CurrentRow Mod 2>onmouseout="this.className='rowOdd'"
<cfelse>onmouseout="this.className='rowEven'"</cfif>>
<td>#qryPersons.CurrentRow#</td>
<td>#qryPersons.LastName#</td>
<input type="hidden" name="FirstName#qryPersons.currentrow#" value="#qryPersons.LastName#">
<td>#qryPersons.FirstName#</td>
<input type="hidden" name="LastName#qryPersons.currentrow#" value="#qryPersons.FirstName#">
<td style="width:50px"><input type="submit" value="Create PDF"</td>
</tr>
</cfloop>
I've never used cfpdfform before, but this syntax should work. You may need to dynamically name the name attribute below as well
<cfpdfform action="populate" source="forms\#form.pdfselect#">
<cfloop from="1" to="50" index="i">
<cfpdfformparam name="FirstName" value="#form['FirstName'&i]#">
<cfpdfformparam name="LastName" value="#form['LastName'&i]#">
</cfloop>
</cfpdfform>