[Colbox 5.6.2] - Flash, Persisting SOME rc keys from a form submission, and thou

Having come off a long stint at a copy with a LOT of home spun solutions and wirebox (only), I know find myself getting reaquainted with the “bigger picture” and at this point in particular with “flash”.

Through CB, I have the most recent flashmessage module installed.

My Coldbox Config has the following segment:

// flash scope configuration
flash = {
scope = “session”,
properties = {}, // constructor properties for the flash scope implementation
inflateToRC = true, // automatically inflate flash data into the RC scope
inflateToPRC = false, // automatically inflate flash data into the PRC scope
autoPurge = true, // automatically purge flash data for you
autoSave = true // automatically save flash scopes at end of a request and on relocations.
};

How I have typically used this in the past was when a form from one handler/action, I would post the results at submit to another handler/action and in there do any additional validation and use flash.message(“blah”,“blah”) to configure a series of “problems” with the forms. If there were any errors logged, for example, in the flash message container, I would then reroute BACK to the original handler/action with the form, display any flash messages in my layout and then repopulate the forms values, when appropriate, with their RC[fieldname] equivalents. To prevent any errors on a first time through, I use event.paramvalue() to configure those same field variables in the initial handler/action.

function create( event, rc, prc ){
prc.whereamiMessage = “Create User”;
prc.onformsubmitaction = “users.processcreateuser”;

event.paramValue( name=“firstname”, value="", private=false )
event.paramValue( name=“lastname”, value="", private=false )
event.paramValue( name=“username”, value="", private=false )
event.paramValue( name=“password”, value="", private=false )

event.setView( “users/create” );
}

Everything works fine except in no way do I seem able to persist the form variables housed in the RC at the time the validation event is executed…

function processcreateuser( event, rc, prc ) {
prc.flash = GetInstance(“Flashmessage@flashMessage”);

if (StructKeyExists(rc, “firstname”) && rc.firstname == “”) {
prc.flash.message(“First Name is Required”, “danger”);
};
if (StructKeyExists(rc, “lastname”) && rc.lastname == “”) {
prc.flash.message(“Last Name is Required”, “danger”);
};
//prc.flash.persistRC(exclude=“event”);
relocate(event=“users.create”);
}

You can see I abandon flahs.persistRC because when I do this, I get a rogue message of type “persistRC”…I understand perhaps WHY that’s happening…but that would not jive with the documentation.

I have tried persistStruct=rc and persist=“rc” on the relocate and the former gets the system “stuck” in a crazy loop of sorts, likely because the original event is still in RC and the latter does nothing helpful, not giving me any errors but not persisting the form values either.

This is a slightly simplified example as “required” I would typically handle other ways, but it illustrates what I’m trying to accomplish, hopefully, enough to trigger an “aha” moment so maybe can put myself out of my misery.

Thanks gang…

Mike

The persist argument in relocate is a list of keys. In your example:

relocate(event="users.create",persist="firstname,lastname");

Although I wouldn’t use relocation between validation & creation but do that in the same call. Like this, you can easily create an entity without validation. You only need to call the “create” event directly

Pascal

Thanks pascal. Ultimately either the flashmessage module does not work with the lastest coldbox because the flash scope is now baked in or I was just implementing it incorrectly. Once I dropped all of the and just used the flash scope my problems mostly just disappeared. While your solution is smart for small forms, the exclude option is a little more helpful with big forms so you don’t have to list every form element you need to persist…though both solutions work fine.

Mike