Page 1 of 1

[Solved] Passing FrontEndUser user data to a FormBuilder form

Posted: Wed Dec 19, 2007 3:12 am
by tosd
Hello,

My setup details - CMSMS: 1.2.2    FEU: 1.3.1    CustomContent: 1.4.10    FormBuilder: 0.4.4

I would like to pass the FEU user data (not just the customcontent_loginname) to a FormBuilder form so that the form is pre-loaded with the logged in user's details.

Aspects of this are covered in various posts and by using the excellent help provided by CalGuy1000 and others I have been able to come up with the following UDT to access the data I need:

-------------------------------------------------------------------------
global $gCms;
$feusers = $gCms->modules['FrontEndUsers']['object'];
if( $feusers )
  {
      $uid = $feusers->LoggedInId();
      $properties = $feusers->GetUserProperties($uid);
      $firstname= ( $properties [1][data]);
      $lastname= ( $properties [2][data]);
      $email= ( $properties [3][data]);
      $phone= ( $properties [4][data]);
      echo $firstname . " " . $lastname . " " . $email . " " . $phone ;
  }
-----------------------------------------------------------------------

So the information is there, I can access it, and (using the test 'echo' statement) I can display it correctly on a page. To pre-load the variables into a FormBuilder form I thought I should be able to use:

{cms_module module='FormBuilder' form='b_tempted' value_fld25= $firstname}

After all, as I have the variable $firstname echoing to the same page as the form I reasoned that it must be accessible. This does not seem to be the case though. I have tried many variations but no matter what I do I cannot seem to get $firstname to pre-load into the form. This would be an incredibly useful thing to be able to do.

If anyone can help with this I would be very grateful. Thanks in advance - Michael.   

Re: Passing FrontEndUser user data to a FormBuilder form

Posted: Wed Dec 19, 2007 3:19 am
by calguy1000
You're 1/2 way there....

Your UDT is in php space, whereas the {cms_module module=FormBuilder...} stuff is in smarty space.

You need to assign the appropriate values to smarty.

i.e:

Here's your udt:

-------------------------------------------------------------------------

Code: Select all

global $gCms;
$feusers = $gCms->modules['FrontEndUsers']['object'];
if( $feusers )
  {
      $uid = $feusers->LoggedInId();
      $properties = $feusers->GetUserProperties($uid);
      $firstname= ( $properties [1][data]);
      $lastname= ( $properties [2][data]);
      $email= ( $properties [3][data]);
      $phone= ( $properties [4][data]);
      echo $firstname . " " . $lastname . " " . $email . " " . $phone ;
  }
-----------------------------------------------------------------------

if you change it to:

-------------------------------------------------------------------------

Code: Select all

global $gCms;
$feusers = $gCms->modules['FrontEndUsers']['object'];
if( $feusers )
  {
      $uid = $feusers->LoggedInId();
      $properties = $feusers->GetUserProperties($uid);
      $firstname= ( $properties [1][data]);
      $lastname= ( $properties [2][data]);
      $email= ( $properties [3][data]);
      $phone= ( $properties [4][data]);

      $smarty->assign('firstname',$firstname);
      $smarty->assign('lastname',$lastname);
      $smarty->assign('email',$email);
      $smarty->assign('phone',$phone);
  }
-----------------------------------------------------------------------

and call this udt above the call to formbuilder, then things would probably just 'work'
btw... this has already been done with the CustomContent module.

Code: Select all

{cms_module module='FormBuilder' form='b_tempted' value_fld25= $ccuser->property('firstname')}
would probably just.... work.

Re: Passing FrontEndUser user data to a FormBuilder form

Posted: Wed Dec 19, 2007 3:53 am
by tosd
Hi CalGuy1000,

You said your suggestion "would probably just.... work"  - and it did ;D That really is an excellent solution. Many thanks for your prompt response.

I have got so much out of your contributions to this forum I would just like to take this opportunity the thank you. The generous way you give your time to help "learners" such as myself is very much appreciated.

Cheers, Michael

Re: Passing FrontEndUser user data to a FormBuilder form

Posted: Wed Dec 19, 2007 3:57 am
by calguy1000
Kudos?

I'm trying to get ahead of cyberman :)

Re: Passing FrontEndUser user data to a FormBuilder form

Posted: Wed Dec 19, 2007 9:29 am
by tosd
Oops, I spoke too soon CalGuy1000 - but you can still have the kudos - it's been earned many times over :)

I checked the solution of assigning the php variables to smarty accessible variables across multiple user data and I discovered that the user properties don't seem to be assigned to the array consistently. To demonstrate this I did a dump of the arrays for two users with the following results:

Array (
  [0] => Array ( [id] => 47 [userid] => 4 [title] => postcode [data] => 3116 )
  [1] => Array ( [id] => 48 [userid] => 4 [title] => state [data] => VIC )
  [2] => Array ( [id] => 49 [userid] => 4 [title] => town [data] => XXXXXX )
  [3] => Array ( [id] => 50 [userid] => 4 [title] => street [data] => XXXXXXXX Court )
  [4] => Array ( [id] => 51 [userid] => 4 [title] => st_number [data] => 4 )
  [5] => Array ( [id] => 52 [userid] => 4 [title] => phone [data] => XX XXXX XXXX )
  [6] => Array ( [id] => 53 [userid] => 4 [title] => email [data] => XXXX@XXXXX.com.au )
  [7] => Array ( [id] => 54 [userid] => 4 [title] => lastname [data] => XXXX )
  [8] => Array ( [id] => 55 [userid] => 4 [title] => firstname [data] => Michael )
  [9] => Array ( [id] => 56 [userid] => 4 [title] => country [data] => Australia )
  [10] => Array ( [id] => 57 [userid] => 4 [title] => dob [data] => 29/09/53 ) )

Array (
  [0] => Array ( [id] => 66 [userid] => 5 [title] => firstname [data] => Sharyn )
  [1] => Array ( [id] => 65 [userid] => 5 [title] => lastname [data] => XXXXX )
  [2] => Array ( [id] => 64 [userid] => 5 [title] => email [data] => XXXXXX@paths2XXXXX.com.au )
  [3] => Array ( [id] => 63 [userid] => 5 [title] => phone [data] => XX XXXX XXXX )
  [4] => Array ( [id] => 62 [userid] => 5 [title] => st_number [data] => 4 )
  [5] => Array ( [id] => 61 [userid] => 5 [title] => street [data] => XXXXX Court )
  [6] => Array ( [id] => 60 [userid] => 5 [title] => town [data] => XXXXXpark )
  [7] => Array ( [id] => 59 [userid] => 5 [title] => state [data] => VIC )
  [8] => Array ( [id] => 58 [userid] => 5 [title] => postcode [data] => 3116 )
  [9] => Array ( [id] => 67 [userid] => 5 [title] => country [data] => Australia )
  [10] => Array ( [id] => 68 [userid] => 5 [title] => dob [data] => 25/10/56 ) )

Note that, for example, the firstname and lastname properties are assigned to different array numbers. This means that calling back the data when referencing the array element gives inconsistent results. The problem seems to be in the way the data is written to the database from the FEU module.

Any suggestions? The other solution by the way of using $ccuser in the module tag I couldn't get to work. I think it is getting hung up with the multidimensional array.

Thanks in advance, Michael.

[Solved] Re: Passing FrontEndUser user data to a FormBuilder form

Posted: Thu Dec 20, 2007 8:13 pm
by tosd
Hello,

After much playing around I have sorted out this problem so I thought someone else may be interested in the result. The UDT (in my case called {member_data} I developed to extract the required property values from the FEU database is as follows:

--------------------------------------------------------------------------------------
global $gCms;
$feusers = $gCms->modules['FrontEndUsers']['object'];
if( $feusers )
  {
      $uid = $feusers->LoggedInId();
      $user_data = $feusers->GetUserProperties($uid);
     
      foreach ($user_data as $record => $row_num) {
 
        foreach ($row_num as $property => $property_data){   
           
          if ($property_data == 'firstname') {
          $firstname = ($user_data [$record] [data]);
          $smarty->assign('firstname',$firstname);
       
          } elseif ($property_data == 'lastname') {
          $lastname = ($user_data [$record] [data]);
          $smarty->assign('lastname',$lastname);
       
          } elseif ($property_data == 'email') {
          $email = ($user_data [$record] [data]);
          $smarty->assign('email',$email);
       
          } elseif ($property_data == 'phone') {
          $phone = ($user_data [$record] [data]);
          $smarty->assign('phone',$phone);
         
          } elseif ($property_data == 'postcode') {
          $postcode = ($user_data [$record] [data]);
          $smarty->assign('postcode',$postcode);
         
          } elseif ($property_data == 'town') {
          $town = ($user_data [$record] [data]);
          $smarty->assign('town',$town);       
          }
          }
        }
        }
-------------------------------------------------------------------------------

A few notes:

1. The line "$user_data = $feusers->GetUserProperties($uid);" fetched the FEU array values.
2. The outer foreach loop iterates through the rows of the multidimensional array.
3. The inner foreach loop iterates through the properties of each row, looking via the elseif statements for the required property - firstname, lastname etc
4.  Lines such as "$firstname = ($user_data [$record] [data]);" return the data (the actual name etc) for the row the elseif selects.
5. Lines such as "$smarty->assign('firstname',$firstname);" make the variables available to smarty tags (see below)

The tag entries in the template to return the variables and call the form are:

-------------------------------------------------------------------------------
{member_data}
{cms_module module='FormBuilder' form='b_tempted' value_fld25= $firstname value_fld26= $lastname value_fld27= $email value_fld28= $phone value_fld29= $postcode value_fld32= $town}
-------------------------------------------------------------------------------

Notes:

1. {member_data} runs the UDT(above) that sets up the variables with the user data and makes them available to the FormBuilder module call.
2. Assignments such as "value_fld25= $firstname" pre-load the returned user data automatically into the form in the matching field. Note that I have used field numbers - field names can also be used.

I hope the info helps someone. Cheers, Michael.

Re: [Solved] Passing FrontEndUser user data to a FormBuilder form

Posted: Sat Feb 09, 2008 4:54 am
by tosd
Yes, the issue of passing FEU data to a Formbuilder form is solved but I am now having difficulty with submission. Essentially, even though the data pre-populates the form (apparently) correctly, submitting the form generates the following error:

"Warning: htmlspecialchars() expects parameter 1 to be string, array given in /home/xxxxxx/public_html/modules/FormBuilder/classes/DispositionEmailBase.class.php on line 145"

When I view source the data appears to be a normal value string.

If the variables are not passed to the form but manually typed in, no errors are generated.

If anyone can help with this I would be very grateful. I have checked other posts but have not come across a solution.

Re: [Solved] Passing FrontEndUser user data to a FormBuilder form

Posted: Sun Sep 26, 2010 12:56 pm
by jtcreate
Good tips....

Rafain, is there a way to do this with the 'email results to' field? I've got an address sitting in a special user property from feu that I'd like to auto-populate the form with, so the form is sent to that address.

Any help is appreciated.

Thx,
Jeff T.

Re: [Solved] Passing FrontEndUser user data to a FormBuilder

Posted: Wed Sep 07, 2011 8:55 am
by leximus
Thanks for all the tips that helped me a lot!

I have called user details this way:
{cms_module module=FrontEndUsers form="silent"}
Thanks again,

Lex