Adventures in Model Glue - Redirecting to an anchor link

I needed to redirect users if they failed a captcha test when submitting a form back to that form. Straightforward enough eh? Not so as the form itself appeared at the bottom of a pages content. Which meant when the user was redirected by model glue he came back to the page but saw no form or any message telling him why he had ended up back here.

Outside of Model Glue it would have been straightforward but in the event handler for the captchaTest, as far as i could see, there was no way to add append an anchor to the end of the url of the view so that model glue would load up the view with the form displaying to the user at the bottom of the page. In other words redirect to a view with its url looking like this index.cfm?event=whatever&var=value#anchorName

What i ended doing to get round this is a complete hack, and will probably have Model Glue users covering their eyes in horror.

Depending on whether the captcha passed or not i had to add either a pass or fail result to event handler. This would allow mg to redirect back to the page ok but not at the form. To get this to happen i had to add an argument to view when the captcha failed, and in the view (gasp!) i had to test for that value, and if it was telling that the captacha failed i had to include a piece of javascript forcing the view to reload at the form.

<!---If redirected here because of captcha fail. Then the JSscript allows the page to be reloaded at
the form once again, ready for captcha to be tried again --->

<cfset variables.cp = viewstate.getValue("captchaError")>
<cfif #variables.cp# is "yes">
<script type="text/javascript" language="javascript">
location.hash = "#captchaFail";
location.reload();
</script>
</cfif>
Ugly i know but it works and is all i could come up with. If anybody has any better ways to get round this then please chip in.

Comments
charlie griefer's Gravatar sounds like you want to look into named results.

in your controller, when the captcha test fails, do the following:

<cfset arguments.event.addResult('failure') />

as soon as the controller encounters this, it will go back to the event handler and look for that specific named result. so in the event-handler in your <results> section, you'd have the following:

<result name="failure" do="myFormEventHandler" preserveState="true" />

see the following page in the model-glue docs for more information:
http://docs.model-glue.com/Reference_Materials/Mod...

hope that helps.
# Posted By charlie griefer | 7/18/08 4:56 AM
Paul's Gravatar Cheers Charlie. Man that was fast - i had not even fully finished writing the entry and you had answered. The preservestate is not something i remember seeing. I'll check it out.
# Posted By Paul | 7/18/08 5:03 AM
Raymond Camden's Gravatar Charlie, that isn't the issue here, or not the main issue. MG doesn't provide a way to go to an event AND a particular hash. Forget about form validation. Imagine you have Page A with links to a FAQ (event=faq). If you wanted to link to a particular question on the FAQ, ie:

index.cfm?event=faq#goober

That would work fine in a link (afaik). But now take the result of some form post, as he had. You can't use the <result> attribute to point to an event AND a hash.

I haven't had my coffee yet so I may be off on this.
# Posted By Raymond Camden | 7/18/08 8:11 AM
todd sharp's Gravatar Might be a bit hackish, but I add the anchor in my form action and it works for me on SlideSix.com

Check out the comments form on the slide show view:

http://slidesix.com/index.cfm?event=slideshow.view...

Go ahead and submit the comment form blank - it will anchor back to the comment form so the errors are immediately visible. Here's how my form tag looks:

<form method="post" name="commentForm" id="commentForm" action="/saveComment##comments"...>

As I said, maybe it's hackish - but it works for me...
# Posted By todd sharp | 7/18/08 8:40 AM
todd sharp's Gravatar Ooops...use this link instead please:

http://slidesix.com/view/Integrating-ColdFusion-8-...
# Posted By todd sharp | 7/18/08 8:42 AM
Raymond Camden's Gravatar Todd - but the idea here though (I believe, still no coffee), is to support it with a RESULT being called, and possibly with redirect=true.
# Posted By Raymond Camden | 7/18/08 9:08 AM
todd sharp's Gravatar Well tell Joe to get to work then ;)
# Posted By todd sharp | 7/18/08 9:12 AM
charlie griefer's Gravatar well i completely misread the question. but if ray's going to use the 'no coffee' excuse, i'm gonna use the 'it was 3:00 am' excuse :)

interesting question (now that i'm kind of awake). as far as the "hack" solution... i'll quote mr. camden and say, "have a coke and get over it". not to advocate hacks in and of themselves, but if you've hit a point where the architecture that you're using simply imposes a particular limitation... what else are you supposed to do?

in this case, you are fully aware that in theory, there should be a better way. and maybe there is, but we just haven't thought of it. still ok. point being, you're not implementing a hack because you're unaware that it's a hack... or for the sake of cutting corners to take a particular shortcut... but in this case because a more elegant solution doesn't seem to be available for a specific scenario.

when the elegant solution is unavailable, your only option is to implement the best available solution that you can devise. i normally throw a little comment into the code to remind myself to come back and revisit it at a later date (not that i ever actually do... but the intent was there) :)
# Posted By charlie griefer | 7/18/08 11:50 AM
todd sharp's Gravatar Just a minor thing really, but the use of pound signs in this line is unnecessary:

<cfif #variables.cp# is "yes">

could really just be:

<cfif variables.cp>
# Posted By todd sharp | 7/18/08 1:00 PM
Joe Rinehart's Gravatar Excuse me for being crude but...omfg. I can't believe I missed this in the docs for 2 (I checked the code to make sure it's supported):

<result do="someOtherEvent" redirect="true" anchor="#comments" />

Supporting line of code from rev 2.0.304:

<cflocation url="#stateContainer.getValue("myself")##arguments.event##appendedState##anchor#" addToken="false" />

-Joe
# Posted By Joe Rinehart | 7/22/08 7:09 AM
# Posted By kijjjn | 10/25/08 1:46 AM
# Posted By one | 10/25/08 1:48 AM
# Posted By two | 10/25/08 1:49 AM
# Posted By sweb | 10/25/08 1:51 AM
# Posted By jjjh | 10/25/08 1:52 AM
# Posted By mikkkk | 11/11/08 3:13 AM
# Posted By ki88 | 11/11/08 3:15 AM
# Posted By olp00 | 11/11/08 3:16 AM
# Posted By ko99 | 11/11/08 3:18 AM
# Posted By iok99 | 11/11/08 3:19 AM
# Posted By mulok | 11/12/08 4:08 AM
# Posted By Bridget Lindquist | 11/24/08 12:20 PM
Air Jordans's Gravatar fgfjhjl;9erfgm,9ory
# Posted By Air Jordans | 12/8/08 10:46 AM
sell wow gold's Gravatar MMOFLY is an exchange site designed specifically for game virtual currencies and items trading.

We are trading mmorpg virtual currency, World of Warcraft account or goods with all of the player. Such as trade world of warcraft gold, wow cd key, wow time card, lotro cdkey and Final fantasy XI cd key, if you want to Sell WOW Gold, Sell LOTRO Gold, Sell Maple Story Mesos, Sell Anarchy Online Credits, Sell EVE Online isk, Sell Lineage 2 Adena, Sell EverQuest 2 plat, Sell FFXI Gil, Sell Guild Wars Gold you can choose us. We will give you a suitable price.

Our specialty is to make a long-term relationship across multiple game players. In meeting the demand of game players to sell, sell and trade in-game currencies and items, MMOFLY offer players with fast transactions, 24-hours customer service and transaction security guaranteed.

Welcome to http://www.mmofly.com
http://www.mmofly.com/cdkey.html" target="_blank">http://www.mmofly.com/cdkey.html
http://www.mmofly.com/trading.html" target="_blank">http://www.mmofly.com/trading.html
# Posted By sell wow gold | 12/22/08 6:19 AM
buy wow gold's Gravatar Today, the Microsoft-owned in-game ad agency said that it has signed an exclusive multiyear agreement with Blizzard. Azerothians opposed to seeing in-game ads in their local <P><A href="http://www.game4power.com/">world of warcft gold</A></P> watering holes need not worry, however, because the deal is limited to Blizzard's Web sites and Battle.net,the game maker's online-gaming hub. Terms of the deal were not announced, but Massive did note that the agreement is applicable to users in the US, Canada, Europe, South Korea, and Australia.
<P><A href="http://www.game4power.com/">buy wow gold</A></P>

Massive also said today that it would be extending its aforementioned deal with Activision to encompass an additional 18 games appearing on the Xbox 360 and PC.<P><A href="http://www.wowgoldone.com/">cheap wow gold</A></P>The agency didn't fully delineate which would fall under this deal, though it did call out Guitar Hero: World Tour, James Bond: Quantum of Solace, and Transformers: Revenge of the Fallen,<P><A href="http://www.itemstores.com/">buy wow items</A></P> as well as games in its Tony Hawk and AMAX Racing franchises.Shortly before Activision and Vivendi announced their deal of the decade,<P><A href="http://www.gamelevelup.com/">wow power leveling</A></P> the Guitar Hero publisher signed on to receive in-game advertisements from Massive Inc for a number of its Xbox 360 and PC games. A bit more than a year later, Massive is now extending its reach to Activision's new power player, Blizzard Entertainment.<P><A href="http://www.game4power.com/">buy wow gold</A></P> from our site ,you'll get more surprises!
# Posted By buy wow gold | 12/28/08 3:15 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner