1. yoji
  2. General
  3. Tuesday, October 13 2015, 10:56 AM
I'm in trouble to set default value.
Please give me some advice or suggestion.

I made a filed which cannot be edit by normal-users.

Visible on profile ... Yes
Visible on edit-profile ... No
Visible on registration ... No

I want to set default value to the field.
So I set a value to the Default Value field in the Options ... tab.
But it doesn't work.

Could someone help me please?
Accepted Answer
admin Accepted Answer
Admin
Hi,
checkbox and select(with multiple options enabled) fields store values into JSON format.

so values should be like ["music","movie"]

so your code become
$data['fieldAlias']='["music","movie"]';
  1. more than a month ago
  2. General
  3. # Permalink
admin Accepted Answer
Admin
Hi,
default value in parameter is only to fill field value in registration form. When a field is not editable then the filled value in form will be deleted.

You can do this by create a simple plugin, follow these steps:
- Download Install and enable skeleton plugin, you can find this at the end of page https://www.easy-profile.com/docs/44-triggers.html
- Open file /plugins/jsn/skeleton/skeleton.php
- remove sample functions like: triggerFieldAvatarUpdate and triggerProfileUpdate
- Create your function to add value after registration, like:
triggerProfileUpdate($user,&$data,$changed,$isNew){ 
if( $isNew ){
$data['here_field_alias']='your_default value';
}
}

This function assign a default value at your field after registration

NOTE: this code is only for example purpose, not tested and not supported.
  1. more than a month ago
  2. General
  3. # 1
yoji Accepted Answer
Basic
Thank you so much for your suggestion.
But I'm still in trouble...

I tried to create new plugin and activated it, then the following error message appears and my site disappears.
Could you please give me some advice?
I checked the page(44-triggers.html) but I cannot find the answer...

I'm appreciate your kind support, and hopefully, give me some more advice...




My code is here:

I made group named 'default'.
And it has a field named 'type'.
I want to set the value 'AAA' to the field.

------------------------------------- code
defined('_JEXEC') or die;

class PlgJsnSkeleton extends JPlugin
{
triggerProfileUpdate($user,&$data,$changed,$isNew){
if( $isNew ){
$data['default/type']='AAA';
}
}
}
  1. more than a month ago
  2. General
  3. # 2
admin Accepted Answer
Admin
Hi you need to write something like this if the alias of your field is "type"

defined('_JEXEC') or die;

class PlgJsnSkeleton extends JPlugin
{
public function triggerProfileUpdate($user,&$data,$changed,$isNew){
if( $isNew )
{
$data['type']='AAA';
}
}
}
  1. more than a month ago
  2. General
  3. # 3
yoji Accepted Answer
Basic
Hi thank you for your support,

It works fine with text field.
But I'm still in another trouble ...
Please help me one more time.

I could set the default value to the text field, but I couldn't set another default value to the checkbox field.
How can I set dafault value to the checkbox field?
  1. more than a month ago
  2. General
  3. # 4
yoji Accepted Answer
Basic
Hi, it solved all of my problems.
Thank you so much!!
  1. more than a month ago
  2. General
  3. # 5
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.
Sorry, the discussion is currently locked. You will not be able to post a reply at the moment.