2
votes

I am using joomla 2.5 with it's default "user profile" plugin that adds extra fields to the profile page of joomla.

I am also using k2 and have a template override setup for the view I am working in:

site/templates/template/html/com_k2/category_item.php

Within that view I can successfully "pull" the data I need using this:

jimport('joomla.user.helper');
$user = & JFactory::getUser();
$profile = JUserHelper::getProfile($user->id);
echo $profile->profile['fieldname'];

My question is really... How can I update this field using jQuery / Javascript without refreshing the page? Unfortunately there is no joomla function like:

JUserHelper::updateProfileField(value,user->id)

Which is what I was hoping to use with jQuery's .ajax()... Anyway, I think I might have to write a function to do this... In which case I probably wouldn't want to modify the core joomla stuff (JUserHelper)... But instead maybe my own? or should I add a function to k2 that can update the joomla user profile data?

btw...The entire point of me doing this is because I want to add a custom "points" field to the user profile page... and I just need a reliable way of reading & updating it (with ajax I think) from the k2 category_item.php view!

Thank You!!!!

1

1 Answers

0
votes

You should write a component to handle the ajax calls, or at the very least add a controller with the tasks you need, i.e. if you're trying to get some json back:

{user:'paul', custom_field_1:'yes and no'}

then in your controller, i.e. com_your_component/controller.php you would have a task such as "getInfo":

function getInfo() {
  // return the json
  echo json_encode($myResultArray);
  exit; // this will make sure you don't get the template etc.
}

and you would send the ajax call to:

http://example.com/index.php?option=com_your_component&task=getInfo&format=json