setFieldAttribute with multiple fieldsets?

29 views
Skip to first unread message

Mike Pearl

unread,
Sep 10, 2016, 7:29:33 PM9/10/16
to Joomla! General Development
I've written a plugin to get some of the registration data from facebook.  In addition, I'm using the user_profile plugin, giving me a few extra fields during registration.  The plugin is getting data from Facebook, then setting the default values on the form fields.

public function onContentPrepareForm($form, $data)
{
 
if(isset($data->socialData)) // $data->socialData populated during onContentPrepareData

 
{
 $form
->setFieldAttribute('name', 'default', $data->socialData->displayName);
 $form
->setFieldAttribute('email1', 'default', $data->socialData->emailVerified);
 $form
->setFieldAttribute('postal_code', 'default', $data->socialData->zip, 'profile');
 $form
->setFieldAttribute('phone', 'default', $data->socialData->phone, 'profile');
 
}

 
return true;
}


The registration form works for the _default fields (name & email1), but is not setting the 'default' values on the postal_code or phone fields, added with the user_profile plugin.  What am I doing wrong?

Mike Pearl

unread,
Sep 10, 2016, 7:30:58 PM9/10/16
to Joomla! General Development
FYI, I'm using Joomla 3.6.

Mike Pearl

unread,
Sep 11, 2016, 1:46:59 PM9/11/16
to Joomla! General Development
I still haven't solved this, but was able to come up with a workaround.  I put the following code In a template override (/templates/mytemplate/html/com_users/registration/default.php).  

if(isset($this->data->socialData))
{
  $this
->form->setValue('name', null, $this->data->socialData->displayName);
  $this->form->setValue('email1', null, $this->data->socialData->email);
  $this
->form
->setValue('postal_code', 'profile', $this->data->socialData->zip);
  $this->form->setValue('phone', 'profile', $this->data->socialData->phone);
}

This works, but seems really kluge.  Still want to set the value in the plugin if anyone has any thoughts.

Thanks again!


Reply all
Reply to author
Forward
0 new messages