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
Jeff SusichJeff Susich 

Web to Lead - Full Name captured instead of First Name, Last Name

I am creating Web-to-Lead HTML, and the website captures the first AND last names in a "Name" field. 

Salesforce wants 'First Name' and 'Last Name' as separate fields. I may not be able to talk them into changing the website form to capture these fields separately. 

What's the best way to deal with this? I could create a custom "Name" field on the Lead object and capture this field, but then how would I best break this up into 'First Name' and 'Last Name'
Best Answer chosen by Jeff Susich
karthikeyan perumalkarthikeyan perumal
Hello, 

use below code with javasscript.. i will take full Name and split it in to first name and last name send to salesfroce. 

Type hidden for Frst name and last name. add new text called name like below. add the onchange event. use the javascript function. 
 
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8">
<script>
function TextCapture(txtid)
{
var OriginalValue=document.getElementById("name").value;
alert(OriginalValue);
document.getElementById("first_name").value=OriginalValue.substr(0,OriginalValue.indexOf(' ')); 
document.getElementById("last_name").value=OriginalValue.substr(OriginalValue.indexOf(' ')+1);;
}
</script>


<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">

<input type=hidden name="oid" value="00D28000000fJRI">
<input type=hidden name="retURL" value="http://">


<label for="name">Name</label><input  id="name" maxlength="80" name="name" size="20" onchange="TextCapture(this)" type="text" /><br>

<input type="hidden" id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>

<input type="hidden" id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>

<label for="email">Email</label><input  id="email" maxlength="80" name="email" size="20" type="text" /><br>

<label for="company">Company</label><input  id="company" maxlength="40" name="company" size="20" type="text" /><br>

<label for="city">City</label><input  id="city" maxlength="40" name="city" size="20" type="text" /><br>

<label for="state">State/Province</label><input  id="state" maxlength="20" name="state" size="20" type="text" /><br>

<input type="submit" name="submit">

</form>

Hope this will help you. 

Mark Best ANSWER if its works for you. 

Thanks
karthik
 

All Answers

karthikeyan perumalkarthikeyan perumal
Hello, 

use below code with javasscript.. i will take full Name and split it in to first name and last name send to salesfroce. 

Type hidden for Frst name and last name. add new text called name like below. add the onchange event. use the javascript function. 
 
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8">
<script>
function TextCapture(txtid)
{
var OriginalValue=document.getElementById("name").value;
alert(OriginalValue);
document.getElementById("first_name").value=OriginalValue.substr(0,OriginalValue.indexOf(' ')); 
document.getElementById("last_name").value=OriginalValue.substr(OriginalValue.indexOf(' ')+1);;
}
</script>


<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">

<input type=hidden name="oid" value="00D28000000fJRI">
<input type=hidden name="retURL" value="http://">


<label for="name">Name</label><input  id="name" maxlength="80" name="name" size="20" onchange="TextCapture(this)" type="text" /><br>

<input type="hidden" id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>

<input type="hidden" id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>

<label for="email">Email</label><input  id="email" maxlength="80" name="email" size="20" type="text" /><br>

<label for="company">Company</label><input  id="company" maxlength="40" name="company" size="20" type="text" /><br>

<label for="city">City</label><input  id="city" maxlength="40" name="city" size="20" type="text" /><br>

<label for="state">State/Province</label><input  id="state" maxlength="20" name="state" size="20" type="text" /><br>

<input type="submit" name="submit">

</form>

Hope this will help you. 

Mark Best ANSWER if its works for you. 

Thanks
karthik
 
This was selected as the best answer
Jeff SusichJeff Susich
Karthik, that's wonderful of you to do this. Excellent work. 
Talles AmadeuTalles Amadeu
That's awesome! Thanks karthikeyan! It works like a charm! Awesome work!
Amanda Turner 9Amanda Turner 9
Does this code work on Pardot forms? It looks like it should but I'm a beginner at this so am not really understanding where the code needs to go and if anything needs to be chaged for it to work on my form. Basically I want to create a form with a Full Name field but the way that SF and Pardot transfers data it uses seperate First and Last Name fields. How do I get the data to from the one Full Name field to seperate into First Name and Last Name fields? Thank you!