Support

  1. cpaschen
  2. General
  3. Wednesday, June 15 2016, 11:40 PM
I need to hide a bunch of fields based on a date (birthdate).
The fields should only be displayed if the user enters a date that is 13 years ago or more (i.e. the person is at least 13 years old).
I've tried to do this several times; however, if I set the comparison to compare dates < (less than) 13 years ago, the fields display when the form hasn't been completed (i.e. the field is blank).

Also, I haven't been able to figure out how to set the proper code to compare against NOW() (I have been only able to set it with a hard-coded date).

Am I missing something?
Can you help me get this working?

Thanks.
admin Accepted Answer
Admin
Hi,
date field store data with format like yyyy-mm-dd so conditions can be like less than "2003" or less than "2003-06-16". unfortunately it is not possible to set a dynamic date.

You can try to manage this with a hidden field type, you can populate this field with javascript in registration/edit profile pages, and in "Compare With" parameter of date field choose hidden field instead "Custom Value". This way is not perfect because when user age change (1 year) the field will be visible until user update his profile.
  1. more than a month ago
  2. General
  3. # 1
cpaschen Accepted Answer
Thanks, that answered the question about the 'NOW()' issue; however, the field is still not performing as you indicate.

In the Condition 1 I have:
Operator - Less than
Compare with - Custom Value
Custom Value - 2003-01-01
Target Field - several other fields on the form
Target Action - Show

However, when the form opens (for editing), the fields are all displayed.
I've also tried the 'inverse' (Greater than / Hide) but still the same thing.

I need the fields to be hidden when the form is first displayed - until the person enters a date (which by the logic you've explained on the conditions should be happening).

Any idea what the problem might be?

[We're using Easy Profile Basic 1.4.3]
  1. more than a month ago
  2. General
  3. # 2
admin Accepted Answer
Admin
Hi,
I have just tried and works, can you please post me your site details to check this?
  1. more than a month ago
  2. General
  3. # 3
cpaschen Accepted Answer
I've added the site details.

The date field is in the Reviewer Profile group titles "Date of Birth".

On the front end you can find it by logging in as the 'author-reviewer' users, then select the DASHBOARD main menu item, then select "EP Profile Review" int he right dashboard menu.
  1. more than a month ago
  2. General
  3. # 4
admin Accepted Answer
Admin
Hi,
yes I see, but this is expected behavior:
for example, this is your condition:
In the Condition 1 I have:
Operator - Less than
Compare with - Custom Value
Custom Value - 2003-01-01
Target Field - several other fields on the form
Target Action - Show
if field is empty: ""<"2003-01-01" this is true so condition show the fields
Inverse condition same thing: "">"2003-01-01" this is false so it show the fields (condition have 2 ways, so instead hide it show the fields)

The problem come when field is empty because seems that the person has least 13 years old

You need to search some workaround for this, for example you can add a javascript that hide fields when date of birth is empty.
  1. more than a month ago
  2. General
  3. # 5
cpaschen Accepted Answer
This really isn't 'logical'. There should be a check to see if the field is 'null' (or empty). Otherwise, a 'less than - hide' will never work properly on any field.
There should at least be a 'not null' comparison option checkbox, so that the generated query does (in this case):
less than X AND not Null

The other option that would be even better would be if we had the ability to write custom query (or at least had the ability to build compound conditions.

This would seem to be a rather basic code change that would greatly improve the functionality of the conditions.
  1. more than a month ago
  2. General
  3. # 6
admin Accepted Answer
Admin
Hi,
sorry for late reply, it was too late for us and our offices were closed.

This really isn't 'logical'
Sorry but I disagree with you, conditions need to have 2 state (true or false), I think that something like ""<"2003-01-01" should not return true (this is not logical).

Otherwise, a 'less than - hide' will never work properly on any field.
We provide a simple conditions to make the product "Easy"

The other option that would be even better would be if we had the ability to write custom query (or at least had the ability to build compound conditions.
This is not so simple, conditions need to works by server (PHP) and client (Javascript) side, It's impossible for us translate a query in both languages without errors. User should be know Javascript and php syntax but this is not "Easy".

Ideas for the future
We think that the solution is to add an option for each conditions to enable or disable "Two ways", with this you can use conditions like this:

Condition 1 (like your)
Operator - Less than
Compare with - Custom Value
Custom Value - 2003-01-01
Target Field - several other fields on the form
Target Action - Show
Two Ways: Yes

Condition 2
Operator - Euqual
Compare with - Custom Value
Custom Value - --empty--
Target Field - several other fields on the form
Target Action - Hide
Two Ways: No

Condition 1 will works normally
Condition 2 will hide field when value is empty but it will not show fields when condition is not met
  1. more than a month ago
  2. General
  3. # 7
cpaschen Accepted Answer
Although that would still limit the extension (I don't see any way to create a condition to check to see if a value is 'between 2 dates' or 'between 2 values'), it would solve the issue that we presently have.

Do you have any idea how soon that might be added?
(Or could you provide us with beta code to help you test? We are still developing our site so we could help test it.)
  1. more than a month ago
  2. General
  3. # 8
admin Accepted Answer
Admin
Although that would still limit the extension (I don't see any way to create a condition to check to see if a value is 'between 2 dates' or 'between 2 values'), it would solve the issue that we presently have.
Sorry but I disagree with you, with my idea this is possible, example:
date between 2 dates (2000-2010):

Condition 1
Operator - Greater than
Compare with - Custom Value
Custom Value - 2000-01-01
Target Field - choose fields
Target Action - Show
Two Ways: Yes

Condition 2
Operator - Greater than
Compare with - Custom Value
Custom Value - 2010-12-31
Target Field - choose fields
Target Action - Hide
Two Ways: No

CASE 1: with value minor than year 2000:
Condition 1: not met, so hide fields
Condition 2: not met, so do nothing
Result: fields hidden (correct)

CASE 2: with value greater than year 2010:
Condition 1: met, so show fields
Condition 2: met, so hide fields
Result: fields hidden (correct)

CASE 3: with value between 2000 and 2010
Condition 1: met, so show fields
Condition 2: met, so do nothing
Result: fields show (correct)

With this are possible all combinations.

Anyway as I already said something like Custom Query is not possible.


Do you have any idea how soon that might be added?
(Or could you provide us with beta code to help you test? We are still developing our site so we could help test it.)
Sorry we not have any code to test, this is only an idea. we will add this on your TODO list, but we not have a timeline.
  1. more than a month ago
  2. General
  3. # 9
cpaschen Accepted Answer
OK ... I see; however, it is confusing (esp. to those who are experienced programmers). As long as you give examples of this sort of thing it will be OK; however, I'd expect a lot of confusion (from those who don't read the documentation).

BTW ... it's not just me that think your 'logic' is a bit hard to understand. I've seen that from a number of people.

Is there any way we can 'sponsor' this type of change to the package - to get it done sooner?
  1. more than a month ago
  2. General
  3. # 10
admin Accepted Answer
Admin
Hi,
I see; however, it is confusing
We provide a simple conditions, equal,not equal,greater than,contains...etc. These operators are very simple, the purpose of user can be complex.
Keep in mind that Easy Profile is a profiler extensions (nothing else) so something like "Value Between to values" is seldom used. We want to keep easy profile simple, about condition we can talk for hours, group conditions, AND/OR operators,initial state of fields, these things are even more complex, in the past we have had to deal with systems like this and the conclusion is that it becomes a hell do the most simple conditions.

it's not just me that think your 'logic' is a bit hard to understand. I've seen that from a number of people.
I not agree with this, this happens 1/2 times a month, then only 1% of users have this problem. For me it is a success.

Is there any way we can 'sponsor' this type of change to the package - to get it done sooner?
No, but we always hear our customer and improve our product to meet their requirements. We already working on this feature.
  1. more than a month ago
  2. General
  3. # 11
cpaschen Accepted Answer
Content Protected
  1. more than a month ago
  2. General
  3. # 12
admin Accepted Answer
Admin
Hi,
Easy Profile not but Joomla have many events, for example you can write a simple user plugin that do this.

you can add some function like this:

public function onContentPrepareData($context, $data){
if( ( JRequest::getVar( 'option','' )=='com_users' && JRequest::getVar( 'layout','' )=='edit' ) && ( !isset( $data->age ) || $data->age=='' || $data->age==null ) ) {
$data->age='2008-10-10';
}
return true;
}

NOTE: replace "age" with alias of your date field.

With this function: if you are on edit profile page and your field is empty then "age" field become "2008-10-10".
This function will not store the value it only load this new value for this page.

Easy Profile extends Joomla user management and Joomla already have all triggers. our Profile update trigger is only useful to make operations between fields in a easy was.
  1. more than a month ago
  2. General
  3. # 13
cpaschen Accepted Answer
Content Protected
  1. more than a month ago
  2. General
  3. # 14
admin Accepted Answer
Admin
Hi,
you can use my previous code to set in a hidden field the current date of 13 years ago, after this you can compare your birthdate with this hidden field instead a custom value.


public function onContentPrepareData($context, $data){
if( ( JRequest::getVar( 'option','' )=='com_users' && JRequest::getVar( 'layout','' )=='edit' ) {
$date13yearsAgo= /* CODE PHP TO GET DATE OF 13 YEARS AGO */
$data->hidden_field=$date13yearsAgo;
}
return true;
}


Is there a place (in a data table or file) where the values for each of the options are stored?
All fields parameters are stored in table #__jsn_fields, but change this is not simple because parameters are stored in JSON format.
  1. more than a month ago
  2. General
  3. # 15
cpaschen Accepted Answer
Thanks!
That is perfect.
  1. more than a month ago
  2. General
  3. # 16
cpaschen Accepted Answer
OK ... I'm back with one more problem related to this birthdate field (BTW ... as I think I've mentioned, this is law in US so this should be useful for others as well).

The work-around that I came up with earlier won't work, because the user data still gets saved in the Joomla User table. According to the law, we can't collect ANY data on users under 13, so saving the user record at all is a problem.

So, I need to override the onUserBeforeSave method of Joomla.
I know how to do that with a Joomla user plugin; however, I'm not at all sure how (IF it is possible) to use data that has been entered into EP profile field BEFORE the data is saved.

In my user plugin I need to have something like:


if (easy_profile_field_alias > "2009-07-01") {
return false;
}

return true;


However, I can't seem to figure out how to get the value from the form, BEFORE the form is saved.

Should that data be available via something like this at that point?


$user=JsnHelper::getUser();
echo $user->field_alias


I'm starting to think it would just be easier (and more useful) to create a plugin that just ads a new user profile field and does all of that checking directly.
  1. more than a month ago
  2. General
  3. # 17
admin Accepted Answer
Admin
Hi,
if user is not stored (onUserBeforeSave) the function JsnHelper::getUser() will not work. You can use data sent via POST, with a code like

$form=JFactory::getApplication()->input->post->get('jform', array(), 'array');
$date_of_birth=$form['field_alias'];
  1. more than a month ago
  2. General
  3. # 18
cpaschen Accepted Answer
That didn't seem to work. So I just tried modifying the existing jsn plugin that I already had (that is working fine using a 'triggerProfileUpdate' function).

I added the following function:


public function onUserBeforeSave($user, $isnew, $data)
{
//************************* Birth Date < 13 years old

$birthDateEntered = $data['date_of_birth'];

$todaysDate = mktime();

$ThirteenyearsAgo = date('Y-m-d',strtotime(date("Y-m-d", mktime()) . " - 13 years"));

if ($birthDateEntered < $ThirteenyearsAgo)
{
JError::raiseWarning(500, 'PLG_USER_BIRTHDATE_WARNING');
$okToSave = false;
}

return $okToSave;


}


The function is working properly. The comparison is working properly also (the error is displayed to the user if the date is less than 13 years); however, the user's form is still saved and the user record created - even though the function is returning 'false', which should stop the save processing.

Is EP overriding the onUserBeforeSave somewhere else, which is causing this to be ignored?
  1. more than a month ago
  2. General
  3. # 19
cpaschen Accepted Answer
Sorry, somehow some content got missed on that last code sample. Here's the actual code sample:


public function onUserBeforeSave($user, $isnew, $data)
{
//************************* Birth Date < 13 years old

$okToSave = true;
$birthDateEntered = $data['date_of_birth'];

$todaysDate = mktime();

$ThirteenyearsAgo = date('Y-m-d',strtotime(date("Y-m-d", mktime()) . " - 13 years"));

if ($birthDateEntered < $ThirteenyearsAgo)
{
JError::raiseWarning(500, 'PLG_USER_BIRTHDATE_WARNING');
$okToSave = false;
}

return $okToSave;

}
  1. more than a month ago
  2. General
  3. # 20
admin Accepted Answer
Admin
Hi,
maybe the problem is JError, it launch a PHP exception and function not works properly.

instead JError try to use this:

$app=JFactory::getApplication();
$app->enqueueMessage(JText::_('PLG_USER_BIRTHDATE_WARNING'),'error');

JError is also deprecated.
  1. more than a month ago
  2. General
  3. # 21
cpaschen Accepted Answer
Thanks for catching that deprecated line (i was using an older piece of code of mine as a snippet).

Unfortunately, that didn't change the problem with the function. The user is still being saved.

I know this function works (i.e. stops the save process) when used in a standard user plugin on a Joomla core user data field. (Although I haven't tested that on a site that also has EP installed.)

Is there anywhere in the EP code that uses/overrides the onBeforeUserSave function?
  1. more than a month ago
  2. General
  3. # 22
cpaschen Accepted Answer
I'm also wondering if it has anything to do with the fact that this is a jsn type plugin and is being effected by the execution order of the plugins.
  1. more than a month ago
  2. General
  3. # 23
admin Accepted Answer
Admin
Hi,
no, Easy Profile do not change the Joomla plugins system, plugins of type "jsn" is used for different purpose but never triggered before store user.

Anyway I have tried a simple plugin with following code and works:

public function onUserBeforeSave($user, $isnew, $new = array())
{
return false;
}


Remove alert message code to try. I think you need to us some other way because the function to get message return always true. See screenshot, with my simple code above I get this message "Registration failed:", so I think you there is a way to add message after ":", but I don't know :(
Attachments (1)
  1. more than a month ago
  2. General
  3. # 24
cpaschen Accepted Answer
OK ... NOW it makes sense.

If the plugins of type jsn don't get run until AFTER the user data is saved, then trying to run an onUserBeforeSave will never work (because it's already been saved).

And creating a user plugin won't work either, because the jsn data isn't available from there.

So ... the bad news is that it looks like we can't use the birthdate field within EP to restrict registration based on age.

Which isn't horrible, it just means we'll have to write this as a custom user profile field plugin with the proper checking.

THANKS!!!! for taking so much time to work through this. I've learned a LOT about EP in this process, and I am definitely NOT going to ask you to add THIS to the EP extension - it's definitely something that would require some significant changes in the EP workflow - and is relatively easy to write as a custom user plugin.

I'll go write that plugin and I'll update this ticket when I have it done (mainly for anyone reading this thread that might also need the same functionality).

Again THANKS for taking time to answer all these questions.
  1. more than a month ago
  2. General
  3. # 25
  • 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.