Build Multilingual Websites with Gridbox

Build Multilingual Websites With Joomla Website Builder Gridbox
Mon. - Fri. 9 am - 5 pm Ask a Question
Remember me

FORMS: Insert php-code

5 days 12 hours ago #1

  • Ronny's Avatar
  • Ronny
  • Posts: 74
Hi :)

I have a PHP-Code (see below) that reads the data from the joomal user profile from the url and transfers it to certain fields. Example of how the code works on this form (BF):

web-dokument.de/maklervollmacht-frank-beispielmann-585


Where can i put this PHP- Code in this form (BaForms)?
Or can this be solved with javascript?

web-dokument.de/datenerfassung-frank-beispielmann-585




PHP-Code:

// ENTER URL ENDING
$urlend = ".html";

// FIELD NAMES AND USER ATTRIBUTES
// enter them in form of [attr,fieldname] e.g. [firstname, vorname]
$data = [
["aboutme","firma"],
["aboutme","firma2"],
["name","name"],
["name","name2"],
["address1","adresse"],
["address1","adresse2"],
["postal_code","plzort"],
["postal_code","plzort2"],
["city","plzort"],
["city","plzort2"],
["address2","ort_der_ihk"],
["favoritebook","registernummer"],
["email", "email"]
];

// get current url
$url = JUri::getInstance();

// filter for name in it
$suburl = explode("/",$url);
$temp = end($suburl);
$temp = explode("-",$temp);
$idtag = end($temp);
$id = str_replace($urlend,"",str_replace("id","",$idtag));

// if name isset, execute the following
if(!empty($id)){

// get user id and email with that name
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('name, email');
$query->from('#__users');
$query->where('id = '.$id);
$db->setQuery($query);
$result= $db->loadObjectList();
$uid = $id;
$uemail = $result[0]->email;
$name = $result[0]->name;

// get user profile from that id
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__user_profiles');
$query->where('user_id = '.$uid.'');
$db->setQuery($query);
$result= $db->loadObjectList();
//print_r($result);

echo "<script type='text/javascript'>setTimeout(setValues,500); function setValues(){";
foreach($data as $touple){
$value = "";
if($touple[0] == "name"){
$value = $name;
}
elseif($touple[0] == "email"){
$value = $uemail;
}
else{
foreach($result as $info){
if($info->profile_key == "profile.".$touple[0]){
$value = $info->profile_value;
break;
}
}
}
// if value has surrounding ", delete
$value = str_replace('"',"",$value);

// get the field, set its value
//if(is_numeric($value)){echo "document.getElementsByName('ff_nm_".$touple[1]."[]')[0].value = ".$value."; ";}
//else{
echo "document.getElementsByName('ff_nm_".$touple[1]."[]')[0].value = (document.getElementsByName('ff_nm_".$touple[1]."[]')[0].value.toString() + '".$value." ' );";
//}
}
echo "}</script>";

}

5 days 11 hours ago #2

  • Vyacheslav's Avatar
  • Vyacheslav
  • Posts: 21317
Hello,
Thank you for contacting us

For User name User Email you can use data tag.


For the rest of the fields to the default value, use the code:
[SQL query = SELECT p.profile_value FROM #__user_profiles AS p LEFT JOIN #__users AS u ON u.id = p.user_id WHERE u.username = '[Username]' AND p.profile_key = 'profile.address1';]

profile.address1 - Replace with what you need

Regards,
Vyacheslav, Balbooa.com

5 days 11 hours ago #3

  • Ronny's Avatar
  • Ronny
  • Posts: 74
Thank you for your prompt reply.

Unfortunately, this variant only works for users who are logged in.

The PHP code above gets the data from the user profile without the user having to be logged in.

Is that also somehow possible with BaForms?

5 days 11 hours ago #4

  • Vyacheslav's Avatar
  • Vyacheslav
  • Posts: 21317
Your script does not work for not logged in and will not work in forms


Regards,
Vyacheslav, Balbooa.com

5 days 11 hours ago #5

  • Ronny's Avatar
  • Ronny
  • Posts: 74
Yes, my script takes the data from the user profile and fills it in the fields. Without the user being logged in (see screenshot).
Attachments:

2 days 13 hours ago #6

  • Vyacheslav's Avatar
  • Vyacheslav
  • Posts: 21317
Unfortunately there is no such possibility.

Regards,
Vyacheslav, Balbooa.com
Powered by Kunena Forum