The order in which events are called are as follows:
The first time the form is displayed:
eFormOnBeforeFormParse
eFormOnBeforeFormMerge
On successful submit
eFormOnBeforeFormParse
eFormOnValidate
eFormOnBeforeMailSent
eFormOnMailSent
On failed submit (failed validation)
eFormOnBeforeFormParse
eFormOnBeforeFormMerge
The events you mention are mutually exclusive, meaning that they are not both called withing the same page request, thus you are trying to pass a variable from one page request to another page request . Isn’t that what forms are good for? The simplest way would appear to be to create a hidden field in your form which is filled with the unique key by the event function. However, the eFormOnBeforeFormMerge isn’t the best place to do this as you’ll run into validation problems later on. You could use the eFormOnBeforeFormParse instead, that is if you can guarantee creating the same key between page requests.
If creating the same (unique) key may proof difficult or impossible you can abandon the hidden field and instead use a session variable. In your event function you first check if the session variable exists and only if not, create one.
<?php
If( !isset($_SESSION['mySessionVar']) ) $_SESSION['mySessionVar'] = createMyUniqueKey();
?>
As the $_SESSION is a super global you have access to it in any of your subsequent event functions.
As for the flash applet, yes you can. Create a place holder in your form where you want flash applet and use the eFormOnBeforeFormParse and eFormOnValidate events.
<?php
function OnBeforeFormParse(&$fields, &$templates){
//set place holder value to the flash markup
$fields['myFlashApplet'] = "<object ...>all your flash html markup here</object>";
return true;
}
function OnValidateFunction(&$fields, &$vMsg, &$rMsg ){
//if there are errors simply remove the flash markup
if(count($vMsg)>0 || count($rMsg)>0) unset($fields['myFlashApplet']);
return true;
}
?>