How to decrypt using Encrypted Field Type
Created 7 years ago by kiltedupGreetings,
I have added a field using the Encrypted Field Type. All fine and can see it is indeed encrypted in db.
However when I come to decrypt, I'm getting this error : "Call to a member function decrypt() on string"
The config is the default, so auto_decrypt is set to false - getting the error when using $entry->thefield->decrypt()
as per docs.
Anyway using this field type / seen this / have any tips?
Ta 😄
OK - I see what is going on but not sure why?
I have a stream with around 15 fields - one of them is the encrypted field type. When the form is first submitted, all fields are entered and checking again, the decrypt is fine.
But I reuse the form again in a couple of places to edit the entry but just 2 of the fields (not the encrypted one) - they are set using $builder->setFields([...])
When that is submitted, the two fields are updated however the encryption is done again on the encrypted field. So my output that I thought was the encryption not working when using ->decorated, is in fact the decrypted value, except it is a decryption of the previous encrypted value !!!!!!!
My head hurts 😄
Is there a way to stop the encrypted field updating like this?
Ta
Aha! You want to skip
those fields. You can do $builder->skipField($slug)
or $builder->setSkips($fieldSlugs)
or a combination of the two (The latter is dictative)
Fields is more about configuration overrides n such.. and simple placement sometimes when no layout.
I'll test on this end momentarily but check for slugs and if it's a multiform builder you'll need to skip it (including prefix) from the parent / muti builder OR without prefix from the child form.
decrypt
is a presenter method so you will need to do$entry->decorated->thefield->decrypt()