6 Replies - 34574 Views - Last Post: 24 October 2006 - 09:27 AM Rate Topic: -----

#1 DeepH2O  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 29-September 06

Popup in ColdFusion code

Posted 29 September 2006 - 01:01 PM

I'm still new to ColdFusion only about 3 months in and we are currently running CF MX 7.0, just upgraded the server from CF MX 6.1.

How do I get a popup message box to show up in ColdFusion?

I can do this without even thinking in Visual Basic, VBScript, or Access, (been doing traditional programming for almost 15 years, web programming is still new to me).

Coldfusion is just driving me crazy with the inability to do something this simple or I'm just not seeing the tag.

Currently I'm resorting to using inline javascript like this
'CF code here
<cfoutput>
<cfif authresult.status IS "AuthenticationFailure">
<!--- The user is valid, but not the password.
no need to tell them which one is wrong will just make it easier to hack
--->
<script src="alertStatus.js" type="text/javascript"></script>

<cfelse>
<!--- There is one other status value, invalid user name.
no need to tell them which one is wrong will just make it easier to hack
--->
<script src="alertStatus.js" type="text/javascript"></script>

</cfif>
</cfoutput>

'-----------------------
'javascript code
alert('The login name or password is incorrect.')

Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Popup in ColdFusion code

#2 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1953
  • View blog
  • Posts: 20,377
  • Joined: 17-March 01

Re: Popup in ColdFusion code

Posted 29 September 2006 - 01:24 PM

Welcome to the ColdFusion world, I think I understand what you're trying to do, but I think you're probably getting some of the methodologies mixed up between web based and non-web based. Remember, ColdFusion is a server side language, java script is a client side language. Any server side code will run each time the page is loaded/reloaded. Client side code can be run based on a variety of events (clicks, mouse over, etc.)

I assume you have a page with a form on it (username/password), this page and form submit to the code you have included above. Then you check if the login was correct and if not you set the authresult.status structure variable to AuthenticationFailure. If the authresult.status variable is AuthenticationFailure then you want to display an alert using javascript.

The code you've shown above will run alertStatus.js (technically not inline) for both true and false conditions... not sure if that is the desired result or not. Unless there is something special in the alertStatus.js, I would simply do this (inline):

<cfoutput>
<cfif authresult.status IS "AuthenticationFailure">
<!--- The user is valid, but not the password.
no need to tell them which one is wrong will just make it easier to hack
--->
<script type="text/javascript">

try_again = confirm('Login Failed, Try Again?');

if(try_again){
	history.back();
}
</script>

<cfelse>
<!--- There is one other status value, invalid user name.
no need to tell them which one is wrong will just make it easier to hack
--->

Success!

</cfif>
</cfoutput>


So what I've done is create a confirm box that alerts them the login was incorrect and asks if they want to try again, if they click OK, it will take them back 1 page (just like hitting the back button) so they can try again.

Remember, web based languages only execute when the page loads and it will run the ENTIRE page. Not like non-web based languages where the code stops and waits for user input. Hope that helps, let me know if you have any questions.
Was This Post Helpful? 0
  • +
  • -

#3 DeepH2O  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 29-September 06

Re: Popup in ColdFusion code

Posted 29 September 2006 - 04:51 PM

Thanks for the quick response. This definitely helps.

Basically what I was looking for was a way of doing that very same function in Coldfusion instead of having to resort to javascript. But I guess that's how it has to be done.

I was just using the code snippet as an example. But I like your solution better using the back.history.

The original code was from wizard code in Dreamweaver. I just didn't like the fact that their method gave away whether the user had incorrectly put in the username or the password. I wanted to make it more along the lines of not letting the user know whether they got the username or password wrong. I wanted to err on the side of security so that if someone was trying to hack in then they would never know which one they got right.

It is definitely taking some getting used doing web development. It completely blows away the way I learned how to program with traditional programming with everything being stateless. Yes you're right I did have my methodologies mixed up. I was still thinking as a traditional programmer.

Now I just have to wrap my head around how to keep people from using the back button once they've logged out, to keep them from resubmitting stuff.

Once again. THANKS!
==========================

View Postskyhawk133, on 29 Sep, 2006 - 01:24 PM, said:

Welcome to the ColdFusion world, I think I understand what you're trying to do, but I think you're probably getting some of the methodologies mixed up between web based and non-web based. Remember, ColdFusion is a server side language, java script is a client side language. Any server side code will run each time the page is loaded/reloaded. Client side code can be run based on a variety of events (clicks, mouse over, etc.)

I assume you have a page with a form on it (username/password), this page and form submit to the code you have included above. Then you check if the login was correct and if not you set the authresult.status structure variable to AuthenticationFailure. If the authresult.status variable is AuthenticationFailure then you want to display an alert using javascript.

The code you've shown above will run alertStatus.js (technically not inline) for both true and false conditions... not sure if that is the desired result or not. Unless there is something special in the alertStatus.js, I would simply do this (inline):

<cfoutput>
<cfif authresult.status IS "AuthenticationFailure">
<!--- The user is valid, but not the password.
no need to tell them which one is wrong will just make it easier to hack
--->
<script type="text/javascript">

try_again = confirm('Login Failed, Try Again?');

if(try_again){
	history.back();
}
</script>

<cfelse>
<!--- There is one other status value, invalid user name.
no need to tell them which one is wrong will just make it easier to hack
--->

Success!

</cfif>
</cfoutput>


So what I've done is create a confirm box that alerts them the login was incorrect and asks if they want to try again, if they click OK, it will take them back 1 page (just like hitting the back button) so they can try again.

Remember, web based languages only execute when the page loads and it will run the ENTIRE page. Not like non-web based languages where the code stops and waits for user input. Hope that helps, let me know if you have any questions.

Was This Post Helpful? 0
  • +
  • -

#4 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1953
  • View blog
  • Posts: 20,377
  • Joined: 17-March 01

Re: Popup in ColdFusion code

Posted 29 September 2006 - 05:17 PM

Honestly, ColdFusion is a TERRIBLE language to make the leap from any language to web because it is soooo similar to HTML, it makes you think the code you write is just part of the web page, when in fact it's not.

Keep in mind that coldfusion is a powerful language, and does have many built in functions and tags that create HTML and Flash, but this is not the norm for web languages. PHP, Ruby, Perl, ASP, and even ColdFusion are languages that allow you to interact with databases, and generate web pages. The languages themselves do not actually create pop up windows, pictures, or control the behaviour of the browser. HTML, Javascript, and CSS would be the markup languages responsible for what the user SEES on their screen. PHP, Ruby, Perl, ASP, ColdFusion, etc. are responsible for generating web pages. Your web browser never sees any of the coldfusion code, so coldfusion wouldn't have a way to create a pop up by itself.

You may want to read up on the <cflogin> tag. It relies on sessions (which are stateful ;)). Instead of using javascript to redirect the user, or prompt them, I would replace the alert with a <cflocation url="path/to/login.cfm"> and this will automatically redirect them back to the login page. They won't have any idea what happend. You are correct, using a client side alert does allow the user to see what happened.

I think the biggest thing to remember when you do web development is that everything is "per page" (unless it's in a session or a cookie). Each time the page is reloaded ALL the variables get reset and the page runs again. The other thing is to make sure you seperate your client side languages (javascript) and your server side language (coldfusion) and remember that coldfusion just generates the web pages which is made out of HTML and such. None of the actual coldfusion is ever seen by the user.

Hope that helps, and remember, we're always here to help you out.

[P.S. Don't use Dreamweaver's built in "code" or whatever, you can use it to type your code by hand, but don't let it build it for you... it'll just make it REALLY confusing when you have to change/understand it.]
Was This Post Helpful? 0
  • +
  • -

#5 DeepH2O  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 29-September 06

Re: Popup in ColdFusion code

Posted 04 October 2006 - 01:45 PM

To be honest I had wanted to do this in ASP.NET originally. I at least had a vauge clue how to do that. Since I had done some ASP pages a few years ago for another company. Corporate did not want to spent the money for another VB license. So got saddled with ColdFusion, because the boss thought it was better....that and we already had an unused Dreamweaver and ColdFusion license. Lucky me.

Heck we already have an SQL Server for the database running on a Win2k3 server. Have to admit I'm not too impressed with the way ColdFusion creates database connections to SQL Server, seems a bit convoluted to me.

The project originally started as an Access database (before I started here) and grew a bit, now they want to let others in the system from remote offices on dial-up to be able to get at the system now too. So that's why the move to the web. Just don't want to hog all that dial-up bandwidth with Access stuff.

I've been handcoding most everything. I noticed very quickly how much of a mess Dreamweaver makes of code. That and Dreamweaver just does not seem to show most of what is created for Coldfusion very well. Dreamweaver definitely has no concept of indenting.

I am making use of some of the Flash features because I have a fairly complex form I have created that will be used for data entry. I know that I'll have to use some java script for input validation. So far I have not found that to be too particularly difficult to make the leap to.

It took me a bit to understand CSS. At first it made absolutely no sense to me how it did what it was doing until I actually had to try and do something with it.

I'm discovering just how much more difficult it is do very simple tasks with web development than it is with traditional programming techniques.


Thanks for the help.


View Postskyhawk133, on 29 Sep, 2006 - 05:17 PM, said:

Honestly, ColdFusion is a TERRIBLE language to make the leap from any language to web because it is soooo similar to HTML, it makes you think the code you write is just part of the web page, when in fact it's not.

Keep in mind that coldfusion is a powerful language, and does have many built in functions and tags that create HTML and Flash, but this is not the norm for web languages. PHP, Ruby, Perl, ASP, and even ColdFusion are languages that allow you to interact with databases, and generate web pages. The languages themselves do not actually create pop up windows, pictures, or control the behaviour of the browser. HTML, Javascript, and CSS would be the markup languages responsible for what the user SEES on their screen. PHP, Ruby, Perl, ASP, ColdFusion, etc. are responsible for generating web pages. Your web browser never sees any of the coldfusion code, so coldfusion wouldn't have a way to create a pop up by itself.

You may want to read up on the <cflogin> tag. It relies on sessions (which are stateful ;)). Instead of using javascript to redirect the user, or prompt them, I would replace the alert with a <cflocation url="path/to/login.cfm"> and this will automatically redirect them back to the login page. They won't have any idea what happend. You are correct, using a client side alert does allow the user to see what happened.

I think the biggest thing to remember when you do web development is that everything is "per page" (unless it's in a session or a cookie). Each time the page is reloaded ALL the variables get reset and the page runs again. The other thing is to make sure you seperate your client side languages (javascript) and your server side language (coldfusion) and remember that coldfusion just generates the web pages which is made out of HTML and such. None of the actual coldfusion is ever seen by the user.

Hope that helps, and remember, we're always here to help you out.

[P.S. Don't use Dreamweaver's built in "code" or whatever, you can use it to type your code by hand, but don't let it build it for you... it'll just make it REALLY confusing when you have to change/understand it.]

Was This Post Helpful? 0
  • +
  • -

#6 wiredwizard  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 76
  • Joined: 07-May 05

Re: Popup in ColdFusion code

Posted 14 October 2006 - 10:38 AM

Just wanted to step in and 2nd Skyhawks message about allowing your IDE to automatically create code for you. Way too many people doing that.

If your going to be using Coldfusion for your backend functions you might want to take a look at Adobe's Spry framework or there Flex framework

This post has been edited by wiredwizard: 14 October 2006 - 10:38 AM

Was This Post Helpful? 0
  • +
  • -

#7 DeepH2O  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 29-September 06

Re: Popup in ColdFusion code

Posted 24 October 2006 - 09:27 AM

I learned pretty quick not to trust Dreamweaver for making code. I've been handcoding most everything. Just did not like how Dreamweaver layed everything out, it pretty much made a mess of things. It did help me out at first to get an idea of how to do some stuff. Like getting NT authentication going against a web page. The examples pretty much sucked and were of almost no use. Ended up using some of the example web sites from the CD for figuring out cookies and stuff and logging out users.

I was going to look at Flex but backed off when we found out how much that stuff cost. Just a bit too pricey for us.

Had not heard of the Spry framework. Will check it out.

Thanks.

View Postwiredwizard, on 14 Oct, 2006 - 10:38 AM, said:

Just wanted to step in and 2nd Skyhawks message about allowing your IDE to automatically create code for you. Way too many people doing that.

If your going to be using Coldfusion for your backend functions you might want to take a look at Adobe's Spry framework or there Flex framework

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1