Autofill with logged in user

Harrington

New Member
Hi Folks,

I am working on autofill for users. I have a form that I would like autofilled from the community builder table but I only want the user to be able to fill in one form and be able to edit that form if they are logged in.

I can get the following happening:

1. If I don't link the logged in user to the form using the -1 / userid menu options, autofill works great and it autofills the users details, however, the user can come back and submit multiple forms.

2. If I link the user using -1 / userid then autofill breaks. I would like it to autofill on a new record only. Selecting autofill on new the autofill doesn't do anything.

Any ideas? Thanks, Matt.
 
OK, I can confirm this, and can see why. Just need to work out the best fix.

NOTE TO SELF ... it's this line in the form model _getQuery(), when the autofill request is run:

PHP:
		$usekey = FabrikWorker::getMenuOrRequestVar('usekey', '', $this->isMambot);

... because the menu item is still the one the main form load is under, which means 'usekey' is set in the menu config. So we end up treating the row load from the autofill table as if it was 'usekey', and end up using the wrong FK.

Trying to work out the best way to approach fixing it.

-- hugh
 
OK, i have a fix for this locally, but I don't want to commit it to github until I've tested it for a while, to see if it has any unforeseen side effects.

If you want to test as well, you need to edit two files:

1) In ./components/com_fabrik/models/form.php, around line 3553, change:

PHP:
		$usekey = FabrikWorker::getMenuOrRequestVar('usekey', '', $this->isMambot);

... to ...

PHP:
		$usekey = FabrikWorker::getMenuOrRequestVar('usekey', '', $this->isMambot, 'var');

2) In /plugins/fabrik_form/autofill/autofill.php, around line 106, where we currently have:

PHP:
		$input->set('resetfilters', 1);

... add a line after that to set 'usekey' to an empty string:

PHP:
		$input->set('resetfilters', 1);
		$input->set('usekey', '');

This forces the data query in the main form model to use the query string value for 'usekey' in preference to the menu config setting, and by setting that query string value to an empty string at the start of the autofill AJAX lookup, turns off 'usekey' handling for this lookup.

The "unforeseen side effects" I'm concerned about are to do with changing the preference for menu vs query string value of 'usekey' in form display. We currently use the menu config value by preference, i.e. if there is a menu config value for this form load, use that. I've flip flopped that preference, so we'll now use a query string value if it exists, in preference to the menu config.

I don't *think* it will have any adverse effect, but it's possible there may be some situation in other Fabrik usage where the query string has a userkey=foo on it, but we want to be using the menu config.

-- hugh
 
G'day Hugh,

I have made the changes above in my local installation as suggested. I still get a Autofill running when I select the form from a menu. It doesn't seem to detect that the logged in user has an existing record. It does an autoload every time whether the form has been submitted or not. I have set the autoload to load on new only in both the main options and "autoload on load" options.

Cheers, Matt.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top