Support

  1. cpaschen
  2. General
  3. Friday, June 10 2016, 07:24 PM
Is there any way to have 'dynamically' calculated fields?

We have 4 text fields ('adjective', 'noun', 'number') where the user enters a word in each. We have a 5th text field that needs to have a concat of those 4 fields.

Ideally the concat would happen live via js (either as the user types, or after they leave each field).

Is there any means within EP that would allow us to do this?

If not, is there a way that we could write our own js so that future EP updates don't break it?

If neither of those is an option, we might be able to just live with it happening upon profile save. Is there any way to do this (other than just writing our own custom plugin to trigger on profileupdate or fieldupdate)?
cpaschen Accepted Answer
THANK YOU!
That is a great help.

And you have GREAT support staff!
  1. more than a month ago
  2. General
  3. # 1
admin Accepted Answer
Admin
Hi,
I have updated the code above, missing WHERE clause in DB query (without this clause the code is very very dangerous). Anyway we recommend to test this code on another environment before use it in production site.
  1. more than a month ago
  2. General
  3. # 2
admin Accepted Answer
Admin
Partially,
because you can do this with Joomla triggers (but it is a bit complex). see docs at https://docs.joomla.org/Plugin/Events/User

You can do something like this:

if ($data['field_alias'] ==0) {
$app=JFactory::getApplication();
$app->enqueueMessage('your message','error');
$app->redirect(JRoute::_('index.php?option=com_jsn&view=profile',false));
}


This code perform a redirect to profile page and add a error message, keep in mind that this code will be triggered before Easy Profile store information but after that Joomla store email, name and username informations. So you can add a code to write in DB (table #__users) the old email/name/username

if ($data['field_alias'] ==0) {

$db=JFactory::getDbo();
$joomlaFields=array(
'name='.$db->quote($user->name),
'email='.$db->quote($user->email),
'username='.$db->quote($user->username)
);
$query=$db->getQuery(true);
$query->update('#__users')->set($joomlaFields)->where('id='.$user->id);
$db->setQuery($query);
$db->execute();

$app=JFactory::getApplication();
$app->enqueueMessage($user->name,'error');
$app->redirect(JRoute::_('index.php?option=com_jsn&view=profile',false));

}


NOTE: this code is not tested and not supported, this is only for example purpose.
  1. more than a month ago
  2. General
  3. # 3
cpaschen Accepted Answer
Is there any way within the updatetrigger to tell EP to NOT save the data (and ideally raise an error)?

i.e.
if ($data['field_alias'] ==0) {
---don't save the record - raise an error ---
}

We'd like to guild that into our concat function so that we don't end up saving something if the contents of a field are not valid.
  1. more than a month ago
  2. General
  3. # 4
cpaschen Accepted Answer
That is even better.

Thanks!
  1. more than a month ago
  2. General
  3. # 5
admin Accepted Answer
Admin
Ideally the concat would happen live via js (either as the user types, or after they leave each field).
Javascript is not recommended because you not have a server validation.

We recommend you to write a simple (very very simple) plugin to do this, this plugin can be based on our skeleton plugin, follow these steps:
- 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)
{
// Example concat
$data['alias_of_field_to_concat'] = $data['field1'] . $data['field2'] . $data['field3'];
// Example sum
$data['alias_of_field_to_sum'] = $data['field1'] + $data['field2'] + $data['field3'];
}

with this way you can do operations between fields, you need only to write your operation ;)
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 knowledges
  1. more than a month ago
  2. General
  3. # 6
  • 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.