Error executing query, using ajax? - coldfusion

I'm updating a query using a form and ajax.
I added a new column (select option) to the form, it work before adding the select option.
I'm trying to get the value of the #dept_id# but i keep getting error
'NetworkError: 500 Error Executing Database Query'.
This has to do with the update query I have in delete_record.cfc.
when adding dept=#selectDept# to the query is when i get the error.
Taking this part off the query works and it updates.
Below its the form and after that its the delete_record.cfc file.
I also made a http://jsfiddle.net/6focvy54/4/
where I poster the ajax call and have the delete_record.cfc file code.
<form method="post" action="" id="confrm_key">
<table >
<tr>
<th >Add?</th>
<th >Delete?</th>
</tr>
<cfoutput query="total">
<tr id="hd#emp_id#">
<td>
<select name="selectDept" >
<option selected="selected" >Select Department</option>
<cfloop query="department">
<option value="#dept_id#">#dept_name#</option>
</cfloop>
</select>
</td>
<td> <input type="checkbox" name="check_delete" value="#emp_id#" >Yes</td>
</tr>
</cfoutput>
</table>
<p><input type="button" name="Submit" value="Remove" onclick="sub_keys();"></p>
</form>

Related

Passing form input using Coldfusion to external URL

I am trying to pass a form input to an external URL to be used somewhere else and perform a certain task. The issue I am having is actually getting the value and passing it. I either get a LotNumber is undefined or an error executing a Cfquery. I tried using CFPARAMhowever I think I misunderstand what cfparam does. Hopefully this is something simple.
Here is some code:
<table border="1" cellpadding="3" cellspacing="0" rules="GROUPS" frame="BOX" width="100%" bordercolor="#C0C0C0" bgcolor="#FFFFFF">
<thead>
<tr height="28">
<td colspan="4"><b>Outstanding Shipping</b></td>
<CFOUTPUT>
<cfparam name="Show_SampleLogSheet.Passed_LotNumber" default="" />
<td align="left" colspan="1">
<input class="frm3" type="text" id="Outstanding_Passed_LotNumber" size="3" maxlength="6" tabindex="25" style="background-color: ##838383;border:1px solid ##000000; color:white">
<form name="Show_SampleLogSheet" class="frm" action="/Buying/Shipping_Advice/Index.cfm?Passed_CustomerID=#Passed_CustomerID#&Passed_ShippingAdviceID=#Get_ShippingAdvice.ShippingAdviceID#&Passed_Lot_Number=#Show_SampleLogSheet.Passed_LotNumber#&Passed_Activate=1" method="post" style="display: inline">
<input type="hidden" name="Passed_CustomerID" value="#Passed_CustomerID#">
<input class="frm3" type="text" name="Passed_LotNumber" value="#Show_SampleLogSheet.Passed_LotNumber#" size="3" maxlength="6" tabindex="25">
</form>
</td>
</CFOUTPUT>
I really appreciate any help.
Thank you
For names are client side. ColdFusion does not need to name them at all. (Code has been somewhat similified
<cfparam name="Passed_LotNumber" default="" />
I don't know what this field is good for. It is not within the form tag, so it is not going to get pushed over on submit.
<input class="frm3" type="text" id="Outstanding_Passed_LotNumber" size="3" maxlength="6" tabindex="25" style="background-color: ##838383;border:1px solid ##000000; color:white">
Real form starts here. Note that passed_LotNumber does not need anything
<form name="Show_SampleLogSheet" class="frm" action="/Buying/Shipping_Advice/Index.cfm?Passed_CustomerID=#Passed_CustomerID#&Passed_ShippingAdviceID=#Get_ShippingAdvice.ShippingAdviceID#&Passed_Lot_Number=#Passed_LotNumber#&Passed_Activate=1" method="post" style="display: inline">
<input type="hidden" name="Passed_CustomerID" value="#Passed_CustomerID#">
<input class="frm3" type="text" name="Passed_LotNumber" value="#Passed_LotNumber#" size="3" maxlength="6" tabindex="25">
Turns out it was some the wrong input name. Here is the fixed code:
<td align="left" colspan="1">
<input class="frm3" type="text" id="Outstanding_Passed_LotNumber" size="3" maxlength="6" tabindex="25" style="background-color: ##838383;border:1px solid ##000000; color:white">
<form name="Show_SampleLogSheet" class="frm" action="/Buying/Shipping_Advice/Index.cfm" method="post" style="display: inline">
<input type="hidden" name="Passed_CustomerID" value="#Passed_CustomerID#">
<input class="frm3" type="text" name="Passed_Lot_Number" size="3" maxlength="6" tabindex="25">
</form>
</td>
There was a parameter that was hidden somewhere else named Passed_Lot_Number instead of Passed_LotNumber. I apologize, this is some super crap code and it's super old thus all of these dumb headaches. Thank you everyone

How to make date and time form values insert into one column?

I have a form where the user selects a date and time. The user's selections represent the time and date they want specific answers, which they enter in the same form, to display. Then I grab the selected values and insert them into a table: cse_result_summary. Right now my code is inserting them correctly.
I'm using this jquery plugin for the date. Time is just a simple select. Something I did not think about before I finish the form was how I would compare today's date to the show_date.
The code below will work for the show_date, but the problem is with the time. Even if the date is greater, but the time is not, it will have to wait for that time to display. I would like it to display at that specific time and date. When its after that date and time it should no longer matter the time it is.
Since I'm inserting the date and time in different columns, I'm wondering if its possible to insert them into one column? That way I will only have to compare todayDate > formDate:
<cfset dtToday = Now() />
<cfif DateFormat(dtToday, "yyyy--mm--dd") gte DateFormat(getdates.show_date)
&& TimeFormat(dtToday) gte timeformat(getdates.show_time)>
different file (form file)
<tr>
<td> Date it will display (Please enter date format mm/dd/yyyy.):</td>
<td><input class="inputDate" id="inputDate"
value="07/01/2014" NAME="date_used"/>
</td>
</tr>
<tr>
<td> Time it will display (Please enter time format hh:mm tt):
<td><select ID="time_used" NAME="time_used" VALIDATE="date" >
<option selected> Select Time</option>
<option value="7:00 AM">7:00 AM</option>
<option value="7:15 AM">7:15 AM</option>
<option value="7:30 AM">7:30 AM</option>
<option value="7:45 AM">7:45 AM</option>
<option value="8:00 AM">8:00 AM</option>
</select></TD>
</td>
</tr>
</tbody>
</table>
<p><input type="submit" name="Submit" value="Submit"></p>
</form>
<cfif FormSubmit eq "FormSubmitted">
... more code....
<cfset month_date_show = #DateFormat(Trim(form.month_date_show), "mm-15-yyyy")#>
<cfset newdate = #DateFormat(Trim(date_used), "mm-dd-yyyy")# />
<cfset time_used = #TimeFormat(Trim(time_used),"h:mm tt")#>
<cfquery datasource="Intranet" name="InsertRequest">
INSERT INTO cse_result_summary
( show_date, show_time,monthly_enter_date,monthly_past_date )
VALUES
( '#newdate#','#time_used#',getdate(),'#month_date_show#' )
</cfquery>
Assuming your database field type is date/time you could do something like this:
<tr>
<td> Date it will display (Please enter date format mm/dd/yyyy.):</td>
<td><input class="inputDate" id="inputDate" value="07/01/2014" NAME="date_used"/>
</td>
</tr>
<tr>
<td> Time it will display (Please enter time format hh:mm tt):
<td><select ID="time_used" NAME="time_used" VALIDATE="date" >
<option selected> Select Time</option>
<option value="7:00 AM">7:00 AM</option>
<option value="7:15 AM">7:15 AM</option>
<option value="7:30 AM">7:30 AM</option>
<option value="7:45 AM">7:45 AM</option>
<option value="8:00 AM">8:00 AM</option>
</select></TD>
</td>
</tr>
</tbody>
</table>
<p><input type="submit" name="Submit" value="Submit"></p>
</form>
<cfif FormSubmit eq "FormSubmitted">
... more code....
<cfset month_date_show = #DateFormat(Trim(form.month_date_show), "mm-15-yyyy")#>
<cfset newdate = #DateFormat(Trim(date_used), "mm-dd-yyyy")# />
<cfset time_used = #TimeFormat(Trim(time_used),"h:mm tt")#>
<Cfset combinedDateTime="#newdate #time_used#">
<cfquery datasource="Intranet" name="InsertRequest">
INSERT INTO cse_result_summary (show_date, show_time,monthly_enter_date,monthly_past_date, *yourcolumname*)
VALUES ('#newdate#','#time_used#',getdate(),'#month_date_show#', <cfqueryparam cfsqltype="cf_sql_timestamp" value="#combinedDateTime#">)
</cfquery>

How to generate dynamic name for a <td> and pass the name of it to server

I have the following code :
{% for assessments in list_assessments%}
<form action="/test/" method="post">{%csrf_token%}
<tr>
<td>{{assessments.assessment_id}}</td>
<td>{{assessments.name}}</td>
<td>{{assessments.assessment_begin_date}}</td>
<td>{{assessments.assessment_end_date}}</td>
<td>{{assessments.is_active}}</td>
<td>{{assessments.is_complete}}</td>
<td>{{assessments.created_at}}</td>
<td>{{assessments.updated_at}}<br></td>
<td><input type="submit" value="Edit Assessment" /></td>
</tr>
{%endfor%}
</form>
All the data here are dynamically coming.
In this following code, i need to assign an name to assessments.name dynamically, something like
<td name="dynamic_name">{{assessment.name}}</td>.
And on clicking the button "Edit Assessment", i want the dynamic_name to be passed and received my the view.
The idea is each assessment has its own set of parameters. I want to display only the parameters related to the name. So if i could pass the value i would be able to do it.
Any help appreciated.
Your ending **</form>** tag should be before for loop.
{% for assessments in list_assessments%}
<form action="/test/" method="post" name="form-{{ assessments.counter }}">{%csrf_token%}
<tr>
<td>{{assessments.assessment_id}}</td>
<td>{{assessments.name}}</td>
<td>{{assessments.assessment_begin_date}}</td>
<td>{{assessments.assessment_end_date}}</td>
<td>{{assessments.is_active}}</td>
<td>{{assessments.is_complete}}</td>
<td>{{assessments.created_at}}</td>
<td>{{assessments.updated_at}}<br></td>
<td><input type="submit" value="Edit Assessment" /></td>
</tr>
</form>
{%endfor%}
Now, You can get specific block values by form name ( see above code ) in javascript as well as in python.
In Javascript,
form = document.getElementByTagName("form")
elems = form.children("td")
elems will give you all td elements.

ColdFusion - Using a cfloop with multiple fields and multiple submit buttons

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>

ColdFusion 9 ReReplace nth occurence of HTML tag

I have the following HTML stored in a variable in ColdFusion 9. I need to insert a new table row after the 4th </tr>. i.e. before the Submit button.
<form name="form1" id="form1" action="" method="post">
<table>
<tr style="visibility:hidden;display:none;"><td> <input type="hidden" id="ref1" name="ref1" value="1" > </td></tr>
<tr style="visibility:hidden;display:none;"><td> <input type="hidden" id="ref2" name="ref2" value="2" > </td></tr>
<tr>
<th style="text-align:left;">Name * </th>
<td><input type="text" name="foo" id="foo" size="30" maxlength="50" value=""></td>
</tr>
<tr>
<th title="Please enter plain text or HTML." style="cursor:help;text-align:left;">Comment * </th>
<td><textarea name="bar" id="bar" cols="40" rows="10" ></textarea></td>
</tr>
<tr>
<th colspan="1"></th>
<td>
<input style="width:80px" type="submit" value="Submit">
<input style="width:80px" type="button" value="Cancel">
</td>
</tr>
</table>
ReReplace seems like the way to go, but I'm having trouble getting the regexp right. Another option would be to split the string and rebuild it with my new HTML in the middle. Any suggestions would be appreciated.
Regex is the wrong tool for this - you want a HTML parser.
Here's how you can do it with JSoup:
<cfsavecontent variable="InputHtml">
[insert code from question]
</cfsavecontent>
<cfsavecontent variable="NewRow">
<tr><th>whatever</th><td>stuff</td></tr>
</cfsavecontent>
<!--- Read "Creating Objects From Jar Files" --->
<cfset jsoup = createObject('java','org.jsoup.Jsoup') />
<cfset HtmlDom = jsoup.parse(InputHtml) />
<cfset HtmlDom.select('tr:eq(4)').after( NewRow ) />
<cfoutput>
<pre>#XmlFormat(HtmlDom.body().html())#</pre>
</cfoutput>
You can see details of what selectors are supported in the JSoup Selector API
If you don't know/care how many lines are in the table, you can do...
HtmlDom.select('table>tbody').append( NewRow )
...to just add the new row at the end.
Creating Objects From Jar Files
The above code most likely wont work instantly if you copy and paste it, because your server doesn't know about JSoup - you need to download the Jar file and put it in a sensible location.
For CF9, you need to copy the jsoup-1.6.3.jar into your {coldfusion}/lib directory then restart the server.
For CF10, you can use this.JavaSettings in your Application.cfc (as described here) to place it in a different location.
For Railo and OpenBD, you can specify the location of the JAR file as a third argument, e.g:
<cfset jsoup = createObject('java','org.jsoup.Jsoup','lib/jsoup-1.6.3.jar') />
I recommend doing this with jQuery:
​$(document).ready(function(){
$($('form tr')[3]).after('<tr><td>row</tr></tr>');
});​
Much easier.