function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JohnWorthJohnWorth 

Help Please - - Include item In Web to Lead Form

Hello, 

 

I'd like to use a web to lead form on a specific product page. In addition to the normal inquiry information (name, address, etc), I'd like to dynamically include the product name from the web page. Is there a simple way of doing this and sending it to Salesforce?

 

Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
CaptainObviousCaptainObvious

 

Here's one idea...
On your product page, identify the product. 
For example, if the product name is in the h1 tag, put the product name in a span and give the span an id:

 

Here's one idea...


On your product page, identify the product. 
For example, if the product name is in the h1 tag, put the product name in a span and give the span an id:

 

 

<h1><span id="sfProduct">My Product</span></h1>

 

 

On your web-to-lead form, add the product as a hidden field:

 

 

<input type="hidden" name="00N4000000XxXxX" id="00N4000000XxXxX" value="" />

 Finally, as a last step in your form validation javascript, add the following:

 

 

var theProduct = document.getElementById('sfProduct').innerHTML;
document.getElementById("00N4000000XxXxX").value = theProduct;

 

 

Make sure to replace 00N4000000XxXxX with YOUR salesforce field id!

 

As long as you identify the product on each new static page, you won't have to modify the web-to-lead form.

 

If you'd prefer, you could even identify your product in a hidden div, and the form will function in the same way:

 

 

<div id="sfProduct" style="display:none;">My Product Name</div>

 

 

 

 

 

All Answers

CaptainObviousCaptainObvious

Since you want to be able to add the product dynamically, how is the product being selected?

 

For example, does the customer visit a specific product page and click a link to the web-to-lead form? Or is the web to lead form included on the specific product page?

 

Basically, you're going to want to use a hidden field to store the product selection. Populating this field will depend on how you access the web to lead form.

JohnWorthJohnWorth

The product would have it's own static page, but we'd be adding products regularly, and I'd rather not have to create a new W2L form for every product. 

 

Yes, the customer would visit a specific page, and the lead form would be on the right side of the page. I'd like to pull the product name somehow into the lead form. 

CaptainObviousCaptainObvious

 

Here's one idea...
On your product page, identify the product. 
For example, if the product name is in the h1 tag, put the product name in a span and give the span an id:

 

Here's one idea...


On your product page, identify the product. 
For example, if the product name is in the h1 tag, put the product name in a span and give the span an id:

 

 

<h1><span id="sfProduct">My Product</span></h1>

 

 

On your web-to-lead form, add the product as a hidden field:

 

 

<input type="hidden" name="00N4000000XxXxX" id="00N4000000XxXxX" value="" />

 Finally, as a last step in your form validation javascript, add the following:

 

 

var theProduct = document.getElementById('sfProduct').innerHTML;
document.getElementById("00N4000000XxXxX").value = theProduct;

 

 

Make sure to replace 00N4000000XxXxX with YOUR salesforce field id!

 

As long as you identify the product on each new static page, you won't have to modify the web-to-lead form.

 

If you'd prefer, you could even identify your product in a hidden div, and the form will function in the same way:

 

 

<div id="sfProduct" style="display:none;">My Product Name</div>

 

 

 

 

 

This was selected as the best answer
JohnWorthJohnWorth

Thank you!