I use a fill script to transfer values to fields. The code works fine.
But: If the customer scrolls back, then the values are transferred multiple times to the fields. How can I prevent this?
Is there an addition to the code like this:
"Transfer value only if field is empty"?
This here is my code:
// ENTER URL ENDING
$urlend = ".html";
// FIELD NAMES AND USER ATTRIBUTES
// enter them in form of [attr,fieldname] e.g. [firstname, vorname]
$data = [
["name","Name_Makler_Startseite"],
["firma","Firma_Makler"],
["firma","Firma_Makler_2"],
["name","Name_Makler"],
["name","Name_Makler_2"],
["name","Name_Makler_Sendebestaetigung"],
["email", "Email_Makler"]
];
echo "<!-- FillForm Script -->";
// 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 id 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 is still not set (because its not found in profile)
if($value == ""){
// search for it in the fields
// get user profile from that id
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('id');
$query->from('#__fields');
$query->where('name = "'.$touple[0].'"');
$db->setQuery($query);
$result= $db->loadObjectList();
// if field is found
if(!empty($result[0]->id)){
$fieldID = $result[0]->id;
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('value');
$query->from('#__fields_values');
$query->where('field_id = '.$fieldID.' AND item_id = '.$uid);
$db->setQuery($query);
$result= $db->loadObjectList();
if(!empty($result[0]->value)){
$value = $result[0]->value;
}
}
}
// 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>";
}
hmm, ok, I need to check it deeply, please give me a little time.
It will be great if you can send to me a backend link and access data so I can make a couple of tests, on email ma@evolutio.hr and please write name of FORM
Falls Sie neu bei Crosstec sind aber bereits einen Formulargenerator bei einem anderen Hersteller gekauft haben, dann bekommen sie von uns einen Rabatt von 25% auf unsere 1-Jahres und Pro-Mitgliedschaften
Wie Sie an den Rabatt kommen?
Schreiben Sie uns einfach eine kurze Email mit beigelegten Kaufbeleg (z.B. PayPal Quittung) an sales@crosstec.org.
Live Support Chat Opened!
Join our Discord chat here and enter the Crosstec channels to receive live support and talk directly to the team!
Wir unterstützen die Joomla Community
Crosstec unterstützt weltweit alle offiziellen Joomla! User Groups und Organisatoren von Joomla! Days die bei Joomla.org registriert sind.
Falls das auf dich zutrifft und du eines unserer Produkte brauchst, schreib uns eine kurze Email an info@crosstec.org und du bekommst eine Flatrate-Mitgliedschaft geschenkt!