TOPIC:

Fill Script - transferred multiple times 3 months 2 weeks ago #276541

  • RonnyM's Avatar Topic Author
  • RonnyM
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 70
  • Thanks: 0
Hi :)

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>";

}


Sunny greetings Ronny

Please Log in or Create an account to join the conversation.

Fill Script - transferred multiple times 3 months 2 weeks ago #276542

  • Mirec's Avatar
  • Mirec
  • Offline
  • Ultimate Breezer
  • Ultimate Breezer
  • Posts: 3265
  • Karma: 2
  • Thanks: 160
Hi,

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

Let me know

regards,
Mirko

Please Log in or Create an account to join the conversation.

Fill Script - transferred multiple times 3 months 2 weeks ago #276545

  • RonnyM's Avatar Topic Author
  • RonnyM
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 70
  • Thanks: 0
ok, sent you an email :)

Please Log in or Create an account to join the conversation.

Fill Script - transferred multiple times 3 months 2 weeks ago #276546

  • Mirec's Avatar
  • Mirec
  • Offline
  • Ultimate Breezer
  • Ultimate Breezer
  • Posts: 3265
  • Karma: 2
  • Thanks: 160
Hi,

oke, I will take a look and back to you as soon as possible

if you have more questions, feel free to ask!

regards,
Mirko

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Moderators: ForumSupport
Time to create page: 0.080 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

September Discount!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!