Support

  1. krnsgrffn
  2. Support
  3. Wednesday, February 05 2020, 08:56 PM
Hi-

I need to check to see if at least one phone number is provided before a user is either created or updated, and if not, throw an error. I enabled the skeleton plugin, but can't figure out how to do it. Here is my code:


defined('_JEXEC') or die;

class PlgJsnSkeleton extends JPlugin
{

public function triggerProfileUpdate($user,&$data,$changed,$isNew){

if ($data['homephone'] == '' && $data['cellphone'] == ''){
JFactory::getApplication()->enqueueMessage('You need at least one phone number.', 'Error');
}
else {
$user->save();
}

}

}


However, when I save a user with no phone numbers, I get no error message and the user is saved. I am sure the fix is simple, I just don't know what it is.

Thanks.
krnsgrffn Accepted Answer
Pro
Got it. Thanks for the solution.
  1. more than a month ago
  2. Support
  3. # 1
admin Accepted Answer
Admin
Hi,
unfortunately this is not so simple, because the function "triggerProfileUpdate" is triggered after the validation process.

You can use this workaround:
- Create a Field of type Text and set it as required called "Home Phone or Cell Phone" (for example with alias phones)
- In your template options add following custom CSS to hide the field
.phones-group{display: none !important}

- In your template options add following custom Javascript code to fill the phones field
jQuery(document).ready(function($){
$('#jform_homephone,#jform_cellphone').change(function(){
$('#jform_phones').val($('#jform_homephone').val()+$('#jform_cellphone').val());
});
});


Basically the value of field "phones" will be populated with homephone and cellphone values, if both field are empty then the form will return a error like "Invalid field: Home Phone or Cell Phone"
  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.