use Yes button on cfmessagebox to submit the form - coldfusion

I can get my yesno cfmessagebox to pop up, but no matter what button is clicked, the result is always to submit. I need the yes button to submit, but the no button to take no action. I have tried to mimic a lot of examples, but nothing seems to work. Any help is appreciated. Thanks
<cfform name="DeleteForm" action="SubmitESPDeleteAction.cfm" method="post" style="margin:30px;" >
<cfinput name="DeleteButton" type="text" required="yes" style="color:red;" >
<cfinput name="ConfirmDelete" type="submit" onclick="javascript:ColdFusion.MessageBox.show('CONFIRMTest')" value="Delete Record" >
<cfmessagebox name="CONFIRMTest" type="confirm" message="Are you sure you would like to delete this record?" buttonType="yesno" >
<script lang="javascript" type="text/javascript" >
function CONFIRMTest(btn)
{if (btn == 'yes')
submit(DeleteForm)
}
</script>

The problem lies in the JavaScript function conditional statement. Rather than specifying a Boolean conditional, the original code is setting the value of btn to "yes".
Before
if (btn = 'yes')
After
if (btn == 'yes')

Related

Ember's input helper need double click to edit in ie11

<div draggable="true">
{{input value="default value" }}
</div>
In ember.js, as above code, when the div element has an attribute 'draggable="true"', on the webpage, the input area must need a double-click to edit in ie-11, but in chrome or firefox, it just need a click event to edit. Has anyone resolved this issue?
seems to be a bug
[IE 11] Input field of type text does not respond to mouse clicks when ancestor node has draggable=true
bad workaround:
<div style="background-color:lightgray" id="dragE" draggable="true">
<input id="inputE" type="text" />
</div>
click on the lightgray background
now the input field support single click
$('#dragE').focus(); <br>
$('#inputE').focus();<br>
was my solution
unfotunately reproducing with pluncer & co. did not work.
Or...set attribute draggable to "false", when the page goes to a production environment.
This worked for us.

Get the name of a html submit button via CGI

I have two submit buttons in a CGI script (in C++). One (value=Submit) simply saves the form data. The other one (value=Save and Reboot) is supposed to save the form data the same way and then reboot.
Essentially, I want to do this:
if(method == "POST")
{
//element 1 saved
//element 2 saved
//etc etc
if(second button is pushed)
//handle reboot code
}
But how do I tell which button was pushed? I saw this question, but it's in php. I'm working in a C++ CGI script. I've been reading through the CGICC documentation, but I can't find anything on identifying which button was pressed.
To be clear, both buttons essentially will do the same thing (a 'POST'), but I need to be able to identify the button so I can reboot if necessary.
Lets say that you have two buttons, one named "Submit", and one named "Save and Reboot":
<form method="POST" action="">
<input type="submit" name="Submit" />
<input type="submit" name="Save and reboot" />
</form>
Now, just check if there is a value set in the POST data with the appropriate name:
form_iterator fsubmit = formData.getElement("Submit");
if( !fsubmit->isEmpty() && fsubmit != (*formData).end()) {
// The sumbit is pressed
}
form_iterator fsaveandreboot = formData.getElement("Save and reboot");
if( !fsaveandreboot->isEmpty() && fsaveandreboot != (*formData).end()) {
// The save and reboot is pressed
}
This is very easy to write once that you understand that the button that was not clicked will not be included in the POST data.

No need of CGI.script_name

Please refer to the following code:
<cfform method="POST" action="#CGI.script_name#">
<p>Enter your Name:
<input name="name" type="text" hspace="30" maxlength="30">
<input type="Submit" name="submit" value="OK">
</cfform>
<cfscript>
function HelloFriend(Name) {
if (Name is "") WriteOutput("You forgot your name!");
else WriteOutput("Hello " & name &"!");
return "";
}
if (IsDefined("Form.submit")) HelloFriend(Form.name);
</cfscript>
Source: http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=UDFs_01.html#1167055
The code runs fine even without CGI.script_name attribute of action field. May I know why it's required then? The description says "Uses the script_name CGI variable to post to this page without specifying a URL. "
The default action of an HTML form is to submit to itself when no action is specified. See this related discussion on the topic: Is it a good practice to use an empty URL for a HTML form's action attribute? (action="")
I always include an action, if for no other reason, to avoid confusion.

ColdFusion variable not set properly

I have a form with some html elements. It has a check box which is by default checked. On click of the submit button it calls the submitForm function
Based on the checkbox condition it has to do the action. If the checkbox is Y, then it has to do one form action and if not checked then another action. Using javascript I have checked whether its checked or not. But I am not able to set the coldfusion variable for this. Always it overwrites the variable.
Below is the code snippet
This is the ColdFusion variable which is used. This is by default set to Y
<cfset form_condn_var = 'Y'/>
function submitForm(){
if (document.getElementById('Show_Final_Model').checked)
{
form.Show_Final_Model.value = 'Y';
}
else{
<cfset form_condn_var = 'N'/>
}
}
<cfif '<cfoutput>#form_condn_var#</cfoutput>' eq 'Y'>
<form id="form1" action="test.cfm" method="POST" target="testmain">
<cfelse>
<form id="form1" action="<cfoutput>#something#</cfoutput>" method="POST" target="_blank" onSubmit="">
</cfif>
It always set the variable form_condn_var as N and it goes to the else condition of the form irrespective of the condition. . But when I alert the value its comes correctly.
I cannot use hidden variable also as the form is not being called initially. Based on the checked condition only it is accessed.
Could somebody please tell me why the form_condn_var gets overwritten irrespective of the condition being checked.
Or is there any other way I can achieve this?
Thanks in advance
Short version
If I have understood your logic correctly then you can replace all of what you pasted with the following <cfif>
<cfif IsDefined('form.Show_Final_Model') AND form.Show_Final_Model EQ 'Y'>
<form id="form1" action="test.cfm" method="POST" target="testmain">
<cfelse>
<form id="form1" action="<cfoutput>#something#</cfoutput>" method="POST" target="_blank" onSubmit="">
</cfif>
Explanation
Your main problem here is that you have got Javascript outside of tags with a coldfusion within them and seem to be confusing what each language does.
First of all Coldfusion renders the HTML. As far as Coldfusion is concerned, the javascript if statement is just text, and so it sees the following logic
<cfset form_condn_var = 'Y'>
<cfset form_condn_var = 'N'>
<cfif form_condn_var EQ 'Y'> <!--- form_condn_var === '<cfoutput>#form_condn_var#</cfoutput>' but much cleaner --->
.......
<cfelse>
.......
</cfif>
In turn leading to the following HTML being rendered
function submitForm(){
if (document.getElementById('Show_Final_Model').checked)
{
form.Show_Final_Model.value = 'Y';
}
else{
}
}
<form id="form1" action="<cfoutput>#something#</cfoutput>" method="POST" target="_blank" onSubmit="">
I suspect in your example you trimmed out some logic though as otherwise that Javascript would be output as plaintext, as it is not within <script> tags.
If you are submitting your checkbox and then setting the form action for the next form (form 2 - after you've chosen the checkbox) I think what you want to do is the following:
<cfparam name="form.Show_Final_Model" default="N"/>
<cfif form.Show_Final_Model IS 'Y'>
<form id="form1" action="test.cfm" method="POST" target="testmain">
<cfelse>
<form id="form1" action="<cfoutput>#something#</cfoutput>"
method="POST" target="_blank" onSubmit="">
</cfif>
This would be on the handler page (after the form is submitted). You would not need the JS function.
If however you are trying to change the action param of your form to something else based on the check or uncheck of the checkbox (in other words - withing the same form) then ALL of your code needs to be javascript and CF has little to do with it. Set 2 variables - action a and action b, check the value of the checked form element and change the form.action value to whichever one you want.
But most importantly get settled in your mind on what is "server side" and what is "client side" .. that's where you are slipping up. good luck :)
I'm not sure if I'm understanding the question correctly, but it would seem that this situation could be handled purely on the action page based on conditional processing based on the result of the form checkbox value. Instead of sending the form to two different action templates based on the value of the checkbox, just process the form accordingly on the action template based on conditional processing of the checkbox form value.

How to validate characters ONLY in ColdFusion CFForm?

I've got a very simple cfform with a single form field:
<cfform action="asdf.cfm" method="post">
<cfinput name="fieldName" type="text" size="20" maxlength="20" required="yes" validate="regex" pattern="[A-Za-z]" message="Only characters are allowed." />
<input type="submit" name="btnSubmit" value="check" />
</cfform>
Theoretically, this would allow ONLY A-Z and a-z in any combination, and must have some content in it.
In practice, I'm able to enter 'a a' and the javascript validation does not complain. Since the 'space' character is not in A-Z and not in a-z, what's going on?
Thanks!
Chris
You are missing the start-of-string and end-of-string anchors:
^[A-Za-z]$
or, more likely:
^[A-Za-z]{1,20}$
Your sample, modified:
<cfform action="asdf.cfm" method="post">
<cfinput name="fieldName" type="text" size="20" maxlength="20" required="yes" validate="regex" pattern="^[A-Za-z]{1,20}$" message="Only characters are allowed." />
<input type="submit" name="btnSubmit" value="check" />
</cfform>
Without those anchors, the regex merely needs to match anywhere, it does not need to match entirely.
personally I would avoid using the built in coldfusion javascript. You will have much more control if you roll your own and it will give you the ability to display errors in other ways than an alert box.
<script>
function checkit() {
var v = document.getElementById("text1").value;
if(!v.match(/^[a-zA-Z]+$/)) {
alert(v + ' contains invalid characters');
return false;
}
return true;
}
</script>
<form onsubmit="return checkit()">
<input type="text" id="text1">
<input type="submit">
</form>
<script>
function checkit() {
var v = document.getElementById("text1").value;
if(!v.match(/^[a-zA-Z\\ \\.\\]+$/)) {
alert(v + ' contains invalid characters');
return false;
}
return true;
}
</script>
<form onsubmit="return checkit()">
<input type="text" id="text1">
<input type="submit">
</form>
Here is also enter and point possible, but how I'm must do to reconoce ä å ö.
Of course thanks for all help, You help so much.
Came across this article while I was searching for a solution of my own. Needed a non-intrusive way to keep people from entering anything by numbers in one field and nothing but letters, numbers or spaces in other fields. I couldn't use pattern="9999" for the numbers as it was not a required field and folks get "yelled at" if they tab through that field. Likewise, could not use pattern="xxx" for the alpha/numeric fields as I also needed to allow spaces.
Leapfrogging from this article and using javascript that previous programmers had developed for that client, I came up with these beautiful handlers, thought I'd share in case someone else needed this elegant solution and ALSO because sometimes I forget and would be able to find this again.
Either in a .js file you include or enclosed in tags:
function numChecker(e)
{
if (!e.value.match(/^[0-9]+$/))
{
e.value = e.value.substring(0.e.value.length -1 );
e.focus();
return false;
}
return true;
}
function charChecker(e)
{
if (!e.value.match(/^[a-zA-Z0-9\ ]+$/))
{
e.value = e.value.substring(0.e.value.length-1);
e.focus();
return false;
}
return true;
}
Then your input or cfinput fields would have OnKeyUp="numChecker(this)" or OnKeyUp="charChecker(this)" in their attributes.
As people type, if they enter an invalid character this script will kick in and simply remove that bad character. No extra buttons to click or alerts to dismiss.