parsing Error When save profile on live site
Opened this issue · 1 comments
I have set up web service where i am fetching all data like profile feilds, blog post etc. But when i run save profile then it give me the followin error..
{"status":-1,"message":"user_save_profile('admin',array('name'=>'Hello','email'=>'hello@gmail.com')) has a parsing error."}
Here is my server side expose code..
function user_save_profile($username, $profile){
if(!$username){
$user = get_loggedin_user();
} else {
$user = get_user_by_username('surajkumar9890');
}
if (!$user) {
throw new InvalidParameterException('registration:usernamenotvalid');
}
$owner = get_entity($user->guid);
$profile_fields = elgg_get_config('profile_fields');
foreach ($profile_fields as $shortname => $valuetype) {
$value = $profile[$shortname];
$value = html_entity_decode($value, ENT_COMPAT, 'UTF-8');
if ($valuetype != 'longtext' && elgg_strlen($value) > 250) {
$error = elgg_echo('profile:field_too_long', array(elgg_echo("profile:{$shortname}")));
return $error;
}
if ($valuetype == 'tags'){
$value = string_to_tag_array($value);
}
$input[$shortname] = $value;
}
$name = strip_tags($profile['name']);
if ($name) {
if (elgg_strlen($name) > 50) {
return elgg_echo('user:name:fail');
} elseif ($owner->name != $name) {
$owner->name = $name;
return $owner->save();
if (!$owner->save()) {
return elgg_echo('user:name:fail');
}
}
}
if (sizeof($input) > 0) {
foreach ($input as $shortname => $value) {
$options = array(
'guid' => $owner->guid,
'metadata_name' => $shortname
);
elgg_delete_metadata($options);
if (isset($accesslevel[$shortname])) {
$access_id = (int) $accesslevel[$shortname];
} else {
// this should never be executed since the access level should always be set
$access_id = ACCESS_DEFAULT;
}
if (is_array($value)) {
$i = 0;
foreach ($value as $interval) {
$i++;
$multiple = ($i > 1) ? TRUE : FALSE;
create_metadata($owner->guid, $shortname, $interval, 'text', $owner->guid, $access_id, $multiple);
}
}else{
create_metadata($owner->guid, $shortname, $value, 'text', $owner->guid, $access_id);
}
}
}
return "Success";
}
if($_SERVER['REQUEST_METHOD'] == "POST"){
expose_function('user.save_profile',
"user_save_profile",
array('username' => array ('type' => 'string'),
'profile' => array ('type' => 'array')
),
"Save user profile information with username",
'POST',
false,
false);
}elseif($_SERVER['REQUEST_METHOD'] == "GET"){
expose_function('user.save_profile',
"user_save_profile",
array('username' => array ('type' => 'string'),
'profile' => array ('type' => 'array')
),
"Save user profile information with username",
'GET',
false,
false);
}
Here is my client side code..
var profileData;
/* Create Object for profile fields and pass in data */
profileData={};
profileData.name='Hello';
profileData.email='hello@gmail.com';
$.ajax({
url:'http://myurl.com/elgg/services/api/rest/json/',
method:'POST',
dataType:'json',
data:{method:'user.save_profile',username:'***',profile:profileData},
success:function(response){
if(response){
$.ajax({
url:'http://myurl.com/elgg/services/api/rest/json/',
method:'POST',
dataType:'json',
/* Afetr Update Get Profile Field With Username and Profile Fields */
data:{method:'user.get_profile',username:'***'},
success:function(response){
if(response){
//$("#response").text(response.result.core.name);
}
}
});
}
}
});
have you tried escaping the the @ character? This project is getting pretty old now and elgg could really do with a fresh restFul interface.