1

I'm using Civicrm 5.58.1 on Wordpress 6.2.2. I've had a QuickForm working for quite some time.

$this->addEntityRef('Location_province', ts('Select Province'), ['entity' => 'state_province','api' => ['params' => ['country_id' => 1039]]]);

$this->addEntityRef('trial_chairperson', ts('Select Trial Chairperson'));

$this->addEntityRef('trial_secretary', ts('Select Trial Secretary'));

All of these now return a "Loading Failed" message to the front end user. User cannot override and enter any text there and these are required fields so the form is now broken.

I know I should update this form to Afform and Angular, but Quickform is easy and its been working for years. Not sure what update would have possibly broken it? Any ideas what I can do to solve this for now?

Thanks Norm

2
  • What version did you upgrade from when it stopped working?
    – Coleman
    Commented Jul 30, 2023 at 20:04
  • I have not upgraded and n a while. More info, I just checked the corresponding back end form and it works? Now I'm confused Commented Jul 30, 2023 at 21:24

1 Answer 1

2

I suspect what you're seeing is a permissions problem. You mentioned it doesn't work for Front-End users but it does work on the back-end.

EntityRef fields work by calling Apiv3 via ajax. For that to work, a user must have either "access CiviCRM" or "access ajax api" permission. Then they must also have permission to see the entities you are referencing. To view contacts, that usually means the "view all contacts" permission.

You definitely don't want to give all those permissions to anonymous users! Fortunately there is a new solution to this problem: switch from $this->addEntityRef() to $this->addAutocomplete(). The new Autocomplete widget uses APIv4 and allows you finer-grained control over permissions. You do not need to grant users any special permission to use it, instead you can give non-permissioned users access to a particular widget via an event listener.

Here are docs on that: https://docs.civicrm.org/dev/en/latest/framework/autocomplete/

1
  • Thanks for this. I had to update the permissions since adding the addAutocomplete() was not defined in my version. I likely need to update my Civi version. This will be temporary until I convert this form to the new format. Commented Jul 31, 2023 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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