4

Is it possible to detect whether a user is filling in a form in the front-end or the back-end? I want to display a status message for the latter, but I don't want it appearing for regular users using the front-end.

I could check the URL manually, but I figure there must be a better way.

Context is: whenever an address is updated we have various lookups to external services going on. It's useful to display an error to our staff if these lookups fail. But I don't want these being shown to regular users when they update their addresses.

  • any point suggesting you use two different forms (clone profile)? one for public, one for admin? – petednz - fuzion Jun 26 '17 at 23:52
2

I'd recommend you ignore the form name/class entirely and display the message based on whether the user has an admin-type role. Then you don't care how the lookup gets invoked, you just show it to administrators, and it's tied to the service lookup rather than the way it got triggered.

  • Thanks! I used this in the end as address data can be updated using a variety of forms. – Andrew West Jun 28 '17 at 11:43
  • 1
    As a slightly tangential observation - external lookups can be unpredictable, so it's best to invoke them in a non-blocking way, e.g. either as a cron job or via ajax, or using the batch api. – Alan Dixon Jun 28 '17 at 15:00
1

It's a little difficult from your question how these checks to external services are configured - but assuming this is a hook, I would use hook_civicrm_postProcess rather than a database-oriented hook, since you'll get the form name right in the parameters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.