• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Pre-fill form with user info from Virtuemart

Pre-fill form with user info from Virtuemart 17 years 2 months ago #1965

  • jdunagan
  • jdunagan's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 9
Can any one help me change this script:
global $my;

if($my->id){
foreach($fields as $i=>$field){
if($field->name=='fullname') $fields[$i]->default_value = $my->name; //Assuming your rsform text field is called \"fullname\"
if($field->name=='email') $fields[$i]->default_value = $my->email; //Assuming your rsform email text field is called \"email\"
}
}

I need it to pull the user information from VirtueMart instead of Joomla! - Does that make sense? I have some billing and shipping fields that I would like to pre-populate in my form so my users don't have to type it in every time. If anyway can help I would really, really appreciate it!

Thanks for your help.<br><br>Post edited by: jdunagan, at: 2008/02/17 12:43
The administrator has disabled public write access.

Re:Pre-fill form with user info from Virtuemart 17 years 2 months ago #2147

  • jdunagan
  • jdunagan's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 9
I'm still having trouble with getting the user info from VirtueMart and I could really use some help. I saw the post on how to get user info from Community Builder so I tried this:
//load the VM fields
$database-&gt;setQuery(\&quot;SELECT * FROM #__vm_user_info WHERE published&gt;0\&quot;«»);
$vm_fields = $database-&gt;loadObjectList();
 
global $my;
//cycle through the RSform fields
foreach($fields as $i=&gt;$field){
    //check if there is an equivalent field in VM
    foreach($vm_fields as $j=&gt;$vm_fields{
        if($field-&gt;name == $vm_fields-&gt;name{
            //if we find the equivalent, we load the value
            if($vm_fields-&gt;table=='#__users') $key = 'id';
            else $key = 'user_id';
            $database-&gt;setQuery(\&quot;SELECT {$vm_fields-&gt;name} FROM {$vm_fields-&gt;table} WHERE {$key} = {$my-&gt;id}\&quot;«»);
            $fields[$i]-&gt;default_value = $database-&gt;loadResult();
        }
    }
}

It didn't work and obviously I do not know anything about writing scripts. Can someone please help?
The administrator has disabled public write access.

Re:Pre-fill form with user info from Virtuemart 17 years 5 days ago #2901

  • oldrock
  • oldrock's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 8
In case you haven't resolved this yet, here's the code I got to work, after a lot of trial and error. It's not very elegant, requiring a SELECT statement for each field. I couldn't get the more elegant approaches with a single SELECT to work.
$my = &amp; JFactory::getUser();
 
if($my-&gt;id){
    foreach($fields as $i=&gt;$field){
        if($field-&gt;name=='name')  $fields[$i]-&gt;default_value = $my-&gt;name; 
        if($field-&gt;name=='email') $fields[$i]-&gt;default_value = $my-&gt;email; 
 
        if($field-&gt;name=='address') {$database-&gt;setQuery(\&quot;SELECT address_1 FROM #__vm_user_info WHERE user_id = {$my-&gt;id}\&quot;«»); 
            $fields[$i]-&gt;default_value = $database-&gt;loadResult();
            }
        if($field-&gt;name=='address2') {$database-&gt;setQuery(\&quot;SELECT address_2 FROM #__vm_user_info WHERE user_id = {$my-&gt;id}\&quot;«»); 
            $fields[$i]-&gt;default_value = $database-&gt;loadResult(); 
            }
        if($field-&gt;name=='city')     {$database-&gt;setQuery(\&quot;SELECT city FROM #__vm_user_info WHERE user_id = {$my-&gt;id}\&quot;«»); 
            $fields[$i]-&gt;default_value = $database-&gt;loadResult(); 
            }   
        if($field-&gt;name=='state')    {$database-&gt;setQuery(\&quot;SELECT state FROM #__vm_user_info WHERE user_id = {$my-&gt;id}\&quot;«»); 
            $fields[$i]-&gt;default_value = $database-&gt;loadResult(); 
            }   
        if($field-&gt;name=='zip')      {$database-&gt;setQuery(\&quot;SELECT zip FROM #__vm_user_info WHERE user_id = {$my-&gt;id}\&quot;«»); 
            $fields[$i]-&gt;default_value = $database-&gt;loadResult(); 
            }   
        if($field-&gt;name=='country')  {$database-&gt;setQuery(\&quot;SELECT country FROM #__vm_user_info WHERE user_id = {$my-&gt;id}\&quot;«»); 
            $fields[$i]-&gt;default_value = $database-&gt;loadResult(); 
            }   
        if($field-&gt;name=='phone')    {$database-&gt;setQuery(\&quot;SELECT phone_1 FROM #__vm_user_info WHERE user_id = {$my-&gt;id}\&quot;«»); 
            $fields[$i]-&gt;default_value = $database-&gt;loadResult(); 
            }   
    }
}

My PHP knowledge is very limited, but this works for me. Hope this helps.
The administrator has disabled public write access.

Re:Pre-fill form with user info from Virtuemart 17 years 5 days ago #2902

  • oldrock
  • oldrock's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 8
In case you haven't resolved this yet, here's the code I got to work, after a lot of trial and error. It's not very elegant, requiring a SELECT statement for each field. I couldn't get the more elegant approaches with a single SELECT to work.
$my = &amp; JFactory::getUser();
 
if($my-&gt;id){
    foreach($fields as $i=&gt;$field){
        if($field-&gt;name=='name')  $fields[$i]-&gt;default_value = $my-&gt;name; 
        if($field-&gt;name=='email') $fields[$i]-&gt;default_value = $my-&gt;email; 
 
        if($field-&gt;name=='address') {$database-&gt;setQuery(\&quot;SELECT address_1 FROM #__vm_user_info WHERE user_id = {$my-&gt;id}\&quot;); 
            $fields[$i]-&gt;default_value = $database-&gt;loadResult();
            }
        if($field-&gt;name=='address2') {$database-&gt;setQuery(\&quot;SELECT address_2 FROM #__vm_user_info WHERE user_id = {$my-&gt;id}\&quot;); 
            $fields[$i]-&gt;default_value = $database-&gt;loadResult(); 
            }
        if($field-&gt;name=='city')     {$database-&gt;setQuery(\&quot;SELECT city FROM #__vm_user_info WHERE user_id = {$my-&gt;id}\&quot;); 
            $fields[$i]-&gt;default_value = $database-&gt;loadResult(); 
            }   
        if($field-&gt;name=='state')    {$database-&gt;setQuery(\&quot;SELECT state FROM #__vm_user_info WHERE user_id = {$my-&gt;id}\&quot;); 
            $fields[$i]-&gt;default_value = $database-&gt;loadResult(); 
            }   
        if($field-&gt;name=='zip')      {$database-&gt;setQuery(\&quot;SELECT zip FROM #__vm_user_info WHERE user_id = {$my-&gt;id}\&quot;); 
            $fields[$i]-&gt;default_value = $database-&gt;loadResult(); 
            }   
        if($field-&gt;name=='country')  {$database-&gt;setQuery(\&quot;SELECT country FROM #__vm_user_info WHERE user_id = {$my-&gt;id}\&quot;); 
            $fields[$i]-&gt;default_value = $database-&gt;loadResult(); 
            }   
        if($field-&gt;name=='phone')    {$database-&gt;setQuery(\&quot;SELECT phone_1 FROM #__vm_user_info WHERE user_id = {$my-&gt;id}\&quot;); 
            $fields[$i]-&gt;default_value = $database-&gt;loadResult(); 
            }   
    }
}

My PHP knowledge is very limited, but this works for me. Hope this helps.<br><br>Post edited by: strafe, at: 2008/10/14 14:48
The administrator has disabled public write access.

Re:Pre-fill form with user info from Virtuemart 16 years 6 months ago #5063

  • tmafort
  • tmafort's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
Hello, I'm having trouble filling the fields of the form with data from the Register VirtueMart, did what is written here, but not cheat the code worked.


Parse error: syntax error, unexpected T_STRING in /home/restricted/home/rnexpress/public_html/rnencomendas/components/com_rsform/controller/functions.php(879) : eval()'d code on line 8

Thanks,

Thiago
The administrator has disabled public write access.

Re:Pre-fill form with user info from Virtuemart 16 years 6 months ago #5070

  • octavian
  • octavian's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 783
  • Thank you received: 110
Hello,

For some reason there were some garbage characters at the end of each line in the above code. I've edited the post and the 'new' code should work perfectly.
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
The administrator has disabled public write access.

Re:Pre-fill form with user info from Virtuemart 14 years 11 months ago #10507

I can't get this code to work no matter how hard I try. Does anyone want to help?
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!