Support

  1. morgan_leecy
  2. Support
  3. Thursday, September 08 2016, 02:27 PM
I am struggling to get something to work using out the box Easy Profile

I have a field user_vat where the user enters their company VAT number (with regex checking the format)
This is a required field

Every hour I have a script that looks for accounts with user_vat filled out (NOT NULL) and checks it against VIES (vat database)

If that check is good, there is a hidden field vat_ok that changes to a 1. At this point I want the user to be unable to change VAT number

So the theory is there

HOWEVER, once vat_ok is set to 1, the user_vat field should disappear or go read only BUT NOT LOSE IT VALUE

I have tried to use the condition statements (if vat_ok = 1 HIDE user_vat) but that blanks the value of user_vat field and still shows it as it is actually required.. though it will not store any value one vat_ok = 1 as it tries to hide it, blanks it, then keep reshowing it

How can I fulfil the above using Easy Profile or is it not possible with the current build

Quick Summary of requirement

user_vat = required field of format ABxxxxxxxxx (up to 11 digits) - working fine
if vat_ok = 1 user_vat goes read only or disappears but does NOT lose the value (this is not set by user, but by a CRON job running checks)

I suppose I could script this to use jQuery to hide the field, but that could be blocked.. or I could use a hidden value of confirmed_vat and propagate it and keep that hidden BUT due to the fact that user_vat is required, its always visible to the user and I cant hide it

Thanks in advance for any ideas that will help me fulfil the above
morgan_leecy Accepted Answer
Pro
Look forwards to trying this, thanks for the detailed support
  1. more than a month ago
  2. Support
  3. # 1
admin Accepted Answer
Admin
Hi,
there are many ways to do this.

I suppose I could script this to use jQuery to hide the field, but that could be blocked
This is not secure, you will not have server validation/check.

Possible solution:
- Create a field called user_vat_tmp. This field will be shown only in edit profile/registration pages
- Set Condition on field vat_ok like this: if equal to custom value "1" hide field user_vat_tmp
- Set field user_vat to not show in edit profile and registration pages
- Now the trick: create a simple plugin that copy value from field user_vat_tmp to field user_vat only if vat_ok=0

Make plugin
- Download, Install and Enable Skeleton Plugin (you will find it at http://docs.easy-profile.com/index.php/article/triggers)
- Open file /plugins/jsn/skeleton/skeleton.php
- remove samples functions: triggerFieldAvatarUpdate, triggerProfileUpdate
- add function like this:

public function triggerProfileUpdate($user, &$data, $changed, $isNew)
{
if( isset( $data['vat_ok'] ) && $data['vat_ok'] != 1 ) {
$data['user_vat'] = $data['user_vat_tmp'];
}
}

docs about our triggers at http://docs.easy-profile.com/index.php/article/triggers

NOTE: This code is not tested and not supported, this is only for example purpose. You need to have a minimum of PHP and Joomla Dev knowledges

Result
if vat_ok = 0 users will have user_vat_tmp in edit profile/registration page, after submit plugin do this: user_vat=user_vat_tmp. So you will have a new value for VAT into field user_vat

if vat_ok = 1 users will not have user_vat_tmp in edit profile/registration page, after submit plugin do nothing so user_vat_tmp="" and user_vat keep correct value
  1. more than a month ago
  2. Support
  3. # 2
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.

Request Support

Support is currently Offline

Support Availability

Working days: Monday to Friday. The support staff is not available on weekends; in the most of cases tickets will not be answered during that time.

Reply time: Depending on the complexity of your support issue it's usually between a few minutes and 24 hours for paid members and about one week for free members. When we expect longer delays we will notify you.

Guidelines

Before you post: read the documentation and search the forums for an answer to your question.

When you post: include Site Details if you request a support (you can use the form below the reply in Site Details tab).

Auto Solved Question: If after a week the author of the post does not reply to a request by moderator, the question will be marked as resolved.

Language: only English

Search Users

Easy Profile® is not affiliated with or endorsed by Open Source Matters or the Joomla Project. Joomla is Free Software released under the GNU/GPL License.