Form PHP Plugin: values with onLoad event are not submitted...

remico

Member
I have a (order) form with some fields (description, price, qty etc.) that have a admin ACL on ADD and EDIT, so the standard user cannot edit these fields. I load values in the fields with the onLoad event and the PHP Form plugin. I use $formModel->data to pre-fill the fields, and this works, I can see the data in the fields on the order form. But when the user submits the form, the pre-filled data is not submitted... how can I solve this?

In short I need to pre-fill some fields that are read only for standard users and can be edited bij admins. If I put the fields on read-only then they are also read only for the admins...

Am I missing something simple here... pulling my hair out on this.
 
Last edited:
I think it is the Access Settings which are stopping the data being updated.

So I think you need to set these so that standard users can update them, but set the elements themselves to read-only (which is a display-related option rather than a security related one).
 
Hi Sophist,

Tanks for your quick response. The problem with read only is that is is read only everywhere and for everyone...

I'm afraid that there is no 'nice' and out-of-the-box solution for my problem...
 
You can also set the element to be read-write but have a javascript on load event to set it to read only.

(Or possibly - though you would need to test this - leave it at read-only and use an on-load event to set it read-write.)

OR...

Leave the Access so that it is read-only for the standard users and do an SQL UPDATE in the pre-load event in the PHP Events plugin (though this would update regardless of whether the user saves the form or not). (Access Levels are not applied to bespoke SQL in PHP plugins.)
 
I can't replicate this. If I set an element's data (either in the element default, or with $this->data in an onLoad) it correct appends the encrypted hidden element data to the form, and uses that for the submitted data. Which is the expected behavior. You should be able to set even ACL protected data that way. The only way you can't do it is through query strings, as we count that as "user input" rather than "system input". If it's set programatically, that's "system input" so isn't subject to ACL's.

-- hugh
 
Hi Hugh,

Thanks for the reply. I set the data onLoad with
PHP:
$formModel->data['fieldname'] = 'value';

I can see the data in the form, but it is not in the data object in a afterProcess script. Default values are working fine.
 
Are you using the full element name? I'm testing with a field element, and doing ...

Code:
$formModel->data['date_test___name']='foo';
$formModel->data['date_test___name_raw']='foo';

Can you inspect your form's page, and make sure there is a 'fabrikHiddenFields' div, with something like this in it:

Code:
<input type="hidden" name="fabrik_vars[querystring][date_test___name]" value="16 1 E">

Those fabrik_vars[querystring] elements should then get added back in to the posted data during processing, in the addEncryptedVarsToArray() method in the main form model:

https://github.com/Fabrik/fabrik/blob/master/components/com_fabrik/models/form.php#L2048

-- hugh
 
I use the full element name and I can see the values in the form, but did not set the raw value, maybe that is the problem... I'll also check the page for the hidden field to be filled. I'll give it a try tomorrow.
Thanks for your time (again).
 
Hi Hugh,

Sorry for the late reaction, but also filling the raw values did the trick. When I fill the raw value in a onLoad script on a field that is read only by ACL the values will be submitted!

Thanks for the help!!!
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top