+ Start a Discussion
beenerbeener 

Consolidating Web-to-lead form fields

Hi All,

I would like my leads to fill a medical from, which has about 30 yes / no questions and some open lines.

I wouldn't like to create a field for each of these. what's a smart way to do this?
I thought perhaps there is a way to compile these fields into one big text document, in which each question and it's answer would be written line after line.
it can then be sent to salesforce as one single large text file.

Any Ideas on how I should implement this?

Thanks
werewolfwerewolf
Why wouldn't you want to create a field for each data element?  That's what fields are for.
beenerbeener
Ahh, I didn't express myself correctly.
OK, let me rephrase:

Is there a quick way of creating 30 fields?

Also, I don't really need these as fields because storing this informationis more of a formality. I don't need to process the information really. If there was an easy way to convert it into a text file, I could generate and store just one field, which could be great.


Thanks
CaptainObviousCaptainObvious
Here's a possible implementation:
 
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<script type="text/javascript">
function compileFields() {
 var compiled="";
 for( i=0; i < document.f.elements['compile'].length; i++ ) {
  //Compile all the fields with the name="compile" attribute
  compiled += document.f.elements['compile'][i].id + "=" + document.f.elements['compile'][i].value + "; "
 }
 document.getElementById("description").value = compiled;
}
</script>
</head>
<body>

 <form action="https://www.salesforce.com/servlet/servlet.WebToLead—encoding=UTF-8" method="POST" name="f">
 <input type=hidden name="oid" value="YOUR_ORG_ID_HERE">
 <input type=hidden name="retURL" value="http://">
 <label for="first_name">First Name: </label><input  id="first_name" maxlength="40" name="compile" size="20" type="text" /><br>
 <label for="last_name">Last Name: </label><input  id="last_name" maxlength="80" name="compile" size="20" type="text" /><br>
 <label for="email">Email: </label><input  id="email" maxlength="80" name="compile" size="20" type="text" /><br>
 <label for="company">Company: </label><input  id="company" maxlength="40" name="compile" size="20" type="text" /><br>
 <label for="city">City: </label><input  id="city" maxlength="40" name="compile" size="20" type="text" /><br>
 <label for="state">State/Province: </label><input  id="state" maxlength="20" name="compile" size="20" type="text" /><br>
 <input type="button" name="btn" value="Test" onclick="javascript&colon;compileFields();" /><br />
 <br />Click the Test button to see the compiled fields:<br />
 <textarea id="description" name="description" rows="3" cols="50"> </textarea><br />
 <br />
 </form>
</body>
</html>

The above is a simple web-to-lead test form. Fill in the fields and click the Test button. The "compiled fields" show up in the textarea. The "Submit" button has been taken out for testing purposes.
 
How it works:
 
The function looks for all the fields with the name="compile" attribute. For each field, it concatenates the field's id, "=", the input field value, and a delimiter "; ". It saves this in a single variable, called "compiled". Finally, it copies the resulting variable to the "description" field.
 
On your web-to-lead form, you would want your submit button to call the compileFields() function to populate the single textarea field. You can hide this field by using the style="display:none;" attribute.
 
This is not exactly "best practices" but since you asked, yes- it can be done :D
werewolfwerewolf
But yes, you can quickly create fields by using the Metadata API.  Just make 1 custom field on Lead and add it to a package.  Then examine that package in the Force.com IDE – you'll see your field in there under the Lead object.  Now copy and paste that field 30 times, changing the name each time.
beenerbeener
HI CaptainObvious

Thanks so much, this is exactly what I wanted and needed.
Wow. I send you a e-hug if you care for one.

Ben
webtoleadwebtolead

Hi 

 

How do you consolidate these values to textarea that already has some text entered.will it not replace the textarea stuff.. 

 

 

CaptainObviousCaptainObvious

You could store the value of the textarea in a temporary variable. Then append that value to the consolidated values.

 

See the updated script:

 

<script type="text/javascript">
function compileFields() {
 var compiled="";
 var textField = document.getElementById("description").value;
 for( i=0; i < document.f.elements['compile'].length; i++ ) {
  //Compile all the fields with the name="compile" attribute
  compiled += document.f.elements['compile'][i].id + "=" + document.f.elements['compile'][i].value + "; "
 }
 compiled += "text field=" + textField;
 document.getElementById("description").value = compiled;
}
</script>