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.
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>
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.
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.
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...
http://slidesix.com/view/Integrating-ColdFusion-8-...
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) :)
<cfif #variables.cp# is "yes">
could really just be:
<cfif variables.cp>
<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
http://www.adapterlist.com
http://www.wowgold800.com
http://www.wowgoldme.com
http://www.wowgoldvip.com
http://www.wowgoldchina.com
http://www.powerleveling365.com
http://www.powerlevelingus.com
http://www.igxee.com
http://wow.igwww.com
http://www.cheap-wow-gold.de
dell Inspiron 1501 Inspiron 6400(7200mAh)
http://www.cheap-laptop-batteries.com/laptop-batte...
DELL XPS M1330
http://www.cheap-laptop-batteries.com/laptop-batte...
DELL XPS 1530
http://www.battery-shop.org/laptop/vgp-bpl2-batter...
SONY VGP-BPL2 VGP-BPS2
http://www.battery-shop.org/laptop/vgp-bpl5-batter...
SONY VGP-BPL5 VGPBPS5
asus A22-P701 , A22-700 ,P22-900
http://www.laptop-battery.org.uk/laptopbattery/asu...
ASUS R2E , R2H , C22-R2
http://www.battery-store.eu/laptopcomputer/1001580...
asus A42-M6
http://www.battery-store.eu/laptopcomputer/1001554...
acer Aspire 5570 Series
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
<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!