Cfinput checkbox checked - checkbox

I can't quite get this to work.
My form has a number of inputs including one checkbox. In my cfquery, I just want to write some simple SQL content that tests to see if the checkbox is checked or not. But my code just ignores it completely. Here's the basics:
<cfform name="form" action="...." format="HTML">
....
<cfinput type="checkbox" name="search_NR" id="search_NR" checked="no" />
<cfinput type="submit" name="submit" value="Search" />
</cfform>
My cfquery is quite extensive, so I'll just put the part relevant to the checkbox here:
<cfif isDefined("form.search_NR")>
AND (tblMain.NR = true)
</cfif>
My thought was that the box wouldn't be defined if it wasn't checked. But whether or not I check the box on the form, the query just ignores this altogether. I just want to add tblMain.NR = TRUE to the rest of the SQL content when the box is checked.

<cfif StructKeyExists(form, "search_NR")>
AND (tblMain.NR = true)
</cfif>

This will correctly display current status and allow user to change if using both <cfForm> and <cfInput type="Checkbox">:
Note: Ensure that <cfParam> tag is before other references to the form element.
<cfparam name="form.search_NR" default="off">
<cfInput name="search_NR" type="Checkbox" checked="#form.search_NR is 'on'#">Some Text Here
When the <cfform> is submitted the value of search_NR is either 'on' or 'off' and can be checked in your query. Remember to add the form. to the element name:
<cfIf form.searchNR EQ 'on'>
...
<cfElse>
...
</cfIf>

Try using method="POST":
<cfform name="form" action="...." format="HTML" method="post">
Otherwise your variables are submitted via the URL scope.

I figured out a solution on my own...
In the form:
<input type="checkbox" name="search_NR" <cfif search_NR is "on"> checked</cfif> />
And on the processing page...
Before the cfquery:
<cfparam name="search_NR" default="off">
And in the query...
<cfif #search_NR# EQ "on" >
AND (tblMain.NR = true)
</cfif>

Related

need help formating type="datetime-local" in ColdFusion (not a cold fusion element)

Ok I have searched for 2 days and thought I found the solution but it's not working maybe I can get a hand here.
I'm trying to allow the user to choose the date and time of their form post. I found the type="datetime-local" which achieves this (even though it's not widely supported by browsers it still seems to work for my purposes.)
form element:
<input name="PostDate" type="datetime-local" (the version of CF which we are using has the cfcalendar deprecated)
My cfform method is "post" and my action is "submit.cfm"
When we get to the submit.cfm page I'm using the following CF code to format the date to go into MSSQL database:
<cfset PostDate=Replace(PostDate,"T"," ","All")><br>
<cfset PostDate = DateTimeFormat (PostDate, "yyyy-MM-dd HH:nn:ss")>
and the output says that the date is formatted correctly:
But... when I try to cfinsert the date into the database it seems like the formatted date was not saved in the #PostDate# variable (this error is being thrown by the MSSQL database server:
And for completeness of information this is how the table in the database is set up:
this is the code for the submit.cfm
<cfmodule template="customTags/front.cfm" >
<cfoutput>
<p>Date before format: #PostDate#</p>
</cfoutput>
<cfset PostDate=Replace(PostDate,"T"," ","All")>
<cfset PostDate = DateTimeFormat (PostDate, "yyyy-MM-dd HH:nn:ss")>
<br>
<cfoutput>
<p>Title: #PostTitle#</p>
<p>Date after format: #PostDate#</p>
<p>Author ID: #UserID#</p>
<p>Category ID: #CategoryID#</p>
<p>Post Text: #Post#</p>
</cfoutput>
<hr>
<!--- Insert the new record --->
<cfinsert datasource="Intranet" tablename="TBL_POST">
<h1>Post Added</h1>
<cfoutput> You have added #Form.PostTitle#.</cfoutput>
</cfmodule>
As a last qualification for this ask I need to say I'm an absolute beginner at ColdFusion (our state agency uses it) and it's been over ten years since I've written an HTML form.
I appreciate all the help I can get.
Thanks to Dan Bracuk I was able to figure out a solution to this problem:
I needed to prefix PostDate with - form. Like this:
<cfset form.PostDate=Replace(form.PostDate,"T"," ","All")><br>
<cfset form.PostDate = DateTimeFormat (form.PostDate, "yyyy-MM-dd HH:nn:ss")>
The reason is that cfinput processes variables in the form scope and the original cfset commands created a variable in the variables scope.
With 'yourtime' out of a postgresql db:
value="#DateTimeFormat(yourtime, 'yyyy-MM-dd')#T#DateTimeFormat(yourtime, 'HH:nn:ss')#"

“Agree on Terms”-checkbox change error message

I use this question "Agree on Terms"-checkbox code to add "Agree on Terms" on my PHP Wordpress Page but i need change error messagge if user not accept the checkbox.
Is possibile?
This is my code use
<form action="#" onsubmit="if(document.getElementById('agree').checked) { return true; } else { alert('Please indicate that you have read and agree to the Terms and Conditions and Privacy Policy'); return false; }">
<input type="checkbox" required name="checkbox" value="check" id="agree" /> I have read and agree to the Terms and Conditions and Privacy Policy
<button type="submit" class="btn" name="reg_user">Register</button>
</form>
Just change this string in your code:
'Please indicate that you have read and agree to the Terms and Conditions and Privacy Policy'
Make sure you don't use ' in your error msg itself - it defines the end of the string.
Edit:
if you remove required name="checkbox" it should work
because if you do have the required name in your code the form itself will check if the checkbox is checked. This would lead to your js code not being executed. Also you should consider puting your js code into a seperate file.

iMacros: Script: Split array on

iMacros Script
I Need to extract 3 radio buttons text, evaluate it against a stored option. So that the correct selection can be made. There are only 3 buttons but the options are dynamic. I can extract text, and if split can eval it with Gematria. My issue is splitting the text so it can be eval'd. The text is separated by
Example of the extraction SQF BOX
SQF BOX
Html I am pulling from
<td class="evenBand" width="60px" align="left">
<input type="radio" name="ordUom0" id="ordUomR0" tabindex="1001" value="SQF" onclick="checkHSUom(0,'SQF','BOX','','SQM',32.93,1.0,1712.36);"
>SQF
<br>
<input type="radio" name="ordUom0" id="ordUomI0" tabindex="1002" value="BOX" onclick="checkHSUom(0,'SQF','BOX','','SQM',32.93,1.0,1712.36);"
>BOX
<input type="hidden" name="orderedUom" id="orderedUom0" value=""
<="" td="">
</td>
DOES NOT WORK
SET !VAR3 EVAL("'{{!VAR2}}'.split(' ')[0].trim();")
SET !VAR5 EVAL("'{{!VAR2}}'.split(' ')[1].trim();")
SET !VAR6 EVAL("'{{!VAR2}}'.split(' ')[2].trim();")
DOES NOT WORK
SET !VAR3 EVAL("'{{!VAR2}}'.split(' ')[0].trim();")
SET !VAR5 EVAL("'{{!VAR2}}'.split(' ')[1].trim();")
SET !VAR6 EVAL("'{{!VAR2}}'.split(' ')[2].trim();")
Perhaps something like this will be helpful to you:
SET !VAR3 EVAL("'{{!VAR2}}'.split(/\s+/)[1];")
SET !VAR5 EVAL("'{{!VAR2}}'.split(/\s+/)[2];")

AEM/CQ: Checkbox is checked saves a Boolean value of TRUE,How to save a Boolean value as FALSE if we Unchecked?

For Example,I have created a check box with below properties
<checkbox1
jcr:primaryType="cq:Widget"
checked="false"
defaultValue="false"
fieldLabel="Sample"
inputValue="true"
name="./sample"
checkboxBoolTypeHint="{Boolean}true"
type="checkbox"
xtype="selection">
<listeners
jcr:primaryType="nt:unstructured"
check="function(isChecked){var panel = this.findParentByType('panel'); var fields = panel.find('name', './sample'); for (var i=0;i<fields.length; i++) {if (fields[i].xtype == 'hidden') { if (isChecked.checked) {fields[i].setDisabled(true);} else {fields[i].setDisabled(false);}}}}"/>
</checkbox1>
<hiddenCheckbox1
jcr:primaryType="cq:Widget"
disabled="{Boolean}true"
ignoreData="{Boolean}true"
name="./sample"
value="{Boolean}false"
xtype="hidden"/>
If we checked/enabled the check box it is showing the property "Sample" like below
sample Boolean true (working fine)
If we Unchecked/disable the checkbox then it is not showing the property "Sample"
Expectation: I want to show Sample Boolean false if we Unchecked/disable the checkbox
You might want to check the documentation of the Sling POST Servlet. This servlet is called when you submit your dialog. It has something called Suffixes which you can use in your dialog to give the POST servlet some hints about what your fields are doing.
One such suffix for example is the #UseDefaultWhenMissing suffix, which should be exactly what you are looking for.
From the documentation:
As described above, #DefaultValue only takes effect if no value is provided for a particular parameter. However, in some cases, such as HTML checkboxes, this isn't sufficient because the parameter isn't submitted at all. To handle this scenario, you can use the #UseDefaultWhenMissing suffixed parameter.
<form method="POST" action="/content/page/first" enctype="multipart/form-data">
<input name="queryIgnoreNoise" class="input" type="checkbox" value="true"/>
<input type="hidden" name="queryIgnoreNoise#DefaultValue" value="false"/>
<input type="hidden" name="queryIgnoreNoise#UseDefaultWhenMissing" value="true"/>
</form>
So what you have to do in your dialog definition is to add two additional hidden fields:
<checkbox1DefaultValue
jcr:primaryType="cq:Widget"
name="./sample#DefaultValue"
value="{Boolean}false"
xtype="hidden"/>
<checkbox1UseDefaultWhenMissing
jcr:primaryType="cq:Widget"
name="./sample#UseDefaultWhenMissing"
value="{Boolean}true"
xtype="hidden"/>
Pay close attention to the names of the fields:
./sample#DefaultValue and ./sample#UseDefaultWhenMissing.
It is the name of the checkbox (sample) plus the name of the two required suffixes: #DefaultValue and #UseDefaultWhenMissing.
There are a few more nice suffixes you can read about in the Sling documentation:
https://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html

Autofill date in textbox in geckofx

I've been trying to fill some textboxes in geckofx 22.0.7. Most of them with success. There are a couple though that resist any change! Both of them allow only numbers to be typed. The first one (the one presented here) is used to receive a date entry. The user only types numbers (not slashes or dashes etc).
The html code follows:
<td class=" dataEntryCol4">
<input id="insertDate" class="ui-inputfield ui-inputmask ui-widget ui-state-default ui-corner-all" type="text" style="width:90px" tabindex="2" value="" name="insertDate" role="textbox" aria-disabled="false" aria-readonly="false" aria-multiline="false">
</td>
My code is this:
GeckoHtmlElement insertDate = document.GetHtmlElementById("insertDate");
insertDate.SetAttribute("value", "08/06/2014");
I also tried using
SendKeys.SendWait("08062014");
SendKeys.SendWait("{TAB}");
I can't get it to work. Any suggestions?
First cast GeckoHtmlElement to a GeckoInputElement then use the Value property.
GeckoInputElement insertDate = (GeckoInputElement)document.GetHtmlElementById("insertDate");
insertDate.Value = "08/06/2014";

Resources