Run redirect AFTER onAfterProcess

chris.paschen

Chris Paschen
I've got a bunch of 'stuff' that I am doing in a PHP file plugin called from the form onAfterProcess.
One of the things that this does is to manually (via a database update query) updates a 'profile_complete_status' field.
When a user clicks the save button I would really like them to be redirected to a different page based on the status of that field.

I created a redirect plugin on the form (when the form is flagged complete):

* do: redirect
* In: front end
* On: Both
* Jump page: a URL on the current site
* Save and Next: No
* Append jump url with data: No
* Condition:
if ('{ked_books_books___profile_complete_status_raw}' == '1')
{
$status = 1;
} else {
$status = 0;
}
return $status;


The redirect works fine without a condition. And it works fine IF the status field is already set to 1 (prior to the run of the onAfterProcess code).
However, if the value of that status field gets saved during the SAVE button click, then the redirect code doesn't see the changed field.

I'm guessing that I'm just running up-against the fact that the redirect form plugin is running AFTER the onAfterProcess code.
If that's the case, is there a different point to process my script so that it would run before the redirect plugin BUT after the form would have saved data to repeat groups (i.e. a databasejoin element with multiple select that is saved to a _repeat## file)?
[One of the things that my custom php script file does is do a count of how many items are selected in different databasejoin fields and then does some calculations based on that.]

Any ideas?
 
I'm a little confused.

Are you saying you want the redirect to base the condition on your the original value of profile_complete_status element, prior to it being modified by your PHP plugin?

Or are you saying that it is not getting the modified value?

If the latter, are you updating the form data, in $formModel->formData or $formModel->formDataWithTableName, in your PHP script, or are you only poking the value into the database?

I suspect what you probably need to do is:

$formModel->formDataWithTableName['ked_books_books___profile_complete_status_raw'] = $whatever;
$formModel->formDataWithTableName['ked_books_books___profile_complete_status'] = $whatever;

... in your PHP plugin script. Then the redirect plugin should pick up that changed value.

-- hugh
 
OK ... that syntax (...formDataWithTableName...) was not one that I tried, so that is probably the problem.
(it wasn't seeing the changes with just '$formModel->formData')

I'm still not always sure which syntax is correct where for updating data within code (even after staring at the wiki explanation for hours).

I ended up just poking it in the db when none of my original attempts worked around a different method.

I'll give this other syntax a try and see if it works.
 
Yeah, the $formModel->formData vs $formModel->formDataWithTableName is a bit of a kludge.

The issue is that during processing to the database, we remove the tablename__ prefix from the data keys in formData, as part of actually writing the query. Which was fine way back when, when Fabrik (then Mosforms) first started. But then we started needing the full element names after processing. But we already had a buttload of code that assumed they'd been removed. So we added formDataWithTableName, which preserves the prefixes, and can be used to read data onAfterProcess.

And it's that array that gets used for placeholder replacements during plugins that run after processing to the db.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top