Hey Peter.
Yes I guess that I could do post AND have the routed url, but then the
user gets the "would you like to repost data" when they hit the back
button and that is what I am trying to avoid.
Interesting idea. Thanks for that. I ended up moving ahead with my
jQuery plugin, and it works pretty damn nice so far.
jquery.routeurlpost.js:
(function( $ ){
$.fn.routeURLPost = function(options) {
// Rebind a new submit handler
this.submit(function(){
var currentUrl = $(this).attr("action");
var url = currentUrl;
for(var i=0; i < options.parameters.length; i++)
{
var the_val = $("[name=" +
options.parameters[i] + "]", $
(this)).val();
url += "/" + encodeURI(the_val);
}
window.location = url;
// Prevent default form submission
return false;
});
};
})( jQuery );
In my view, I apply this plugin to a form by:
$("#children_form").routeURLPost({
"parameters": ["page", "pageSize", "orderBy", "orderDirection",
"keywords"]
});
It takes the order of the parameters array to build a routed url. The
plugin uses the original action element of the form (which contains
the start of the route url), and then overrides the submit handler. It
loops over the parameters, building up a url, and halts the form from
posting. It then does a browser redirect to the new url. Pretty
simple. I am doing an encodeURI() on all of the parameters to perform
the escaping. So far it works perfectly on all kinds of ugly keywords
that could be entered.
It generates the url:
http://dev.site.com/manage-children-list/1/4/firstName/ASC/billy+bob
-Brian
On Dec 3, 12:19 am, "Peter J. Farrell" <[email protected]> wrote:
> I've used a POST to get a good URL and the JS route as well. Depends on
> the how clean you want things and security needs. You can't trust that
> people won't muck around with the JS stuff or defeat it.
>
> If you are going with the JS generated URLs, the simplest manner is to
> use RegEx replacements by creating a "placeholder" (with defaults) type URL
>
> new MyChildHandler('#buildUnescapedRouteUrl("manage-childern-list",
> "page={page:1}|pageSize={pageSize:4}|orderBy={orderBy:firstName}|orderDirection={orderDirection:ASC}|keywords={keywords})#');
>
> Which generates:
>
> http://dev.site.com/manage-children-list/{page:1}/{pageSize:4}/{orderBy:firstName}/{orderDirection:ASC}/{keywords:}/
>
> You would just RegEx to replace those placeholders in which you have
> data for and then afterwards look for any placeholder you didn't have
> data for and replace with the default that is already in the placeholder.
>
> MyChildHandler.buildManageChildernListUrl({page:1, orderBy:'lastName'});
>
> This way is nice because if you change your route defaults or add new
> parameters, they are already there and you don't have to adjust your JS
> (unless you change your parameter names).
>
> My .02,
> .pjf
>
> Brian H. said the following on 12/02/2010 11:07 PM:
>
> > I have a route setup called /manage-children-list/ which displays a
> > typical "manager" screen, outputting "paged" results, with a search
> > keywords box, etc.
>
> > The route is defined with optional parameters like:
>
> > <parameter name="manage-children-list">
> > <struct>
> > <key name="event" value="manage.children.list" />
> > <key name="optionalParameters" value="page:1,pageSize:
> > 4,orderBy:firstName,orderDirection:ASC,keywords:''" />
> > </struct>
> > </parameter>
>
> > So the listing page could take the form of:
>
> >http://dev.site.com/manage-children-list/1/4/firstName/ASC/billybob/
>
> > Generating links internally using BuiltRouteURL is great, except that
> > I am just realizing that there is nothing allowing me to easily post
> > this form (in GET mode) with a properly routed url. The goal is that
> > when a user reaches:
>
> >http://dev.site.com/manage-children-list/
>
> > And selects the order column, page number, page size, and types in
> > some keywords, the URL that the form submits to will be:
>
> >http://dev.site.com/manage-children-list/1/4/firstName/ASC/billybob/
>
> > I started writing a jquery plugin where I could do something like
> > this:
>
> > $("#children_form").routeURLPost({
> > "parameters": ["page", "pageSize", "orderBy",
> > "orderDirection"]
> > });
>
> > My plan was to have the plugin overwrite the submit() handler for the
> > form, and using the order of the array elements of "parameters", I
> > could build a slash delimited url based on the values of all of those
> > elements. Then I would dynamically change the "action" property of
> > the form and then submit.
>
> > I realize now that I am going to have to manually clean my keywords so
> > that the users don't type in garbage that messes up the url. I am
> > hoping that I can simply use the javascript encodeURI() function to
> > clean any textfields like keywords before throwing in the url.
>
> > Obviously I won't be submitting all of my forms this way. Only forms
> > where the resultant URL could actually be bookmarked and used
> > afterwords.
>
> > It also occurred to me that I could alternatively POST the form to
> > some server-side redirect where the server would take the form fields,
> > use BuildRouteURL, and then redirect to that URL. It seems like a bit
> > more traffic (two page requests) but maybe worth it to keep the JS
> > logic low and make the site more friendly for non-JS folks (who the
> > hell are those guys anyways?).
>
> > Any thoughts?
>
> > -Brian
--
You received this message because you are subscribed to Mach-II for CFML list.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/mach-ii-for-coldfusion?hl=en
SVN: http://svn.mach-ii.com/machii/
Wiki / Documentation / Tickets: http://trac.mach-ii.com/machii/