By Anthony Glover on Tuesday, 27 May 2014
Posted in Technical Issues
Replies 3
Likes 0
Views 1.4K
Votes 0
I'm trying to use the function setFieldValue from \includes\user\user.php line 1482

It works fine for setting single values, however some fields require multiple pieces of data, be it checkboxes, addresses, name etc.

I've tried running a bunch of data through it in what I thought would be an acceptable format (associated array, normal array, object) as it seems to be built to handle them.

However no matter what I do, it's being rejected! If the support team could tell me the specific format in which this function accepts array or object data, and give and example for the name field it would be very helpful.

Name data is in the following format
$value->first = 'Jon';
$value->middle = 'Alexander';
$value->last = 'Doe;'
$name-> 'Jon Alexander Doe';


update -
This function also fails to update if the value was null to start with! Even for single values.
Hi Mark,

It's quite counter-intuitive but I figured it out. I will leave it here as a reference for others.

setFieldValue can be used to set complex data by passing an object or array to it. However in some cases doing this will cause the 'raw' field to fill incorrectly. Example as follows

$esuser = Foundry::user($uid);

$value->first = 'Jon';
$value->middle = 'Alexander';
$value->last = 'Doe;'
$value->name 'Jon Alexander Doe';

$esuser->setFieldValue( 'JOOMLA_FULLNAME' , $value )

Gives
Data : {first:'Jon',middle:'Alexander',last:'Doe',name:'Jon Alexander Doe'}
Raw: Jon Alexander DoeJon Alexander Doe

Which is obviously not good!

However the data and raw fields can be individually specified. In this case it no longer json encodes the array for you.

$esuser = Foundry::user($uid);

$value->first = 'Jon';
$value->middle = 'Alexander';
$value->last = 'Doe;'
$value->name 'Jon Alexander Doe';

$valueholder->data = json_encode($value);
$valueholder->raw = $value->name;

$esuser->setFieldValue( 'JOOMLA_FULLNAME' , $valueholder );

Will give correct output.


Support team, a little more time on the docs would save a lot of time in the forums!
·
Wednesday, 28 May 2014 09:04
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello Anthony,

If you passed in an 'object' as the field value, it would automatically convert it into a json string that is stored in the `jos_social_fields_data`.`data` column and the `raw` column will be imploded by a "space".
·
Wednesday, 28 May 2014 00:59
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks for the heads up on this Anthony
·
Wednesday, 28 May 2014 11:25
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post