Working around Date/Time field issues in Web to Lead forms

2 minute read time.

The feature 'Web to Lead' in Sage CRM enables you to create web pages for collecting lead information automatically. The process generates the HTML to define a web form page for entering lead details. This HTML page can be inserted into a corporate website. The Lead details captured by the form get entered directly into the CRM database.

The generated HTML contains the URL of the CRM installation and defines the action to be taken when the web lead form is submitted. The generated HTML is customizable and there allows a person implementing this feature to add or remove fields from the form but no HTML scripting is required to make the form fully functional.

BUT in Sage CRM problems may arise when attempting to add Date/Time fields to the Web To Lead form.

If the 'webLeadScreen' is customised to include a new custom date/time field e.g. lead_mydatetime, and the WebLeadHtml option is used to generate the HTML then the generated HTML creates a web form like this:

<Form Name=“WEB2LEAD” method=”POST” ………..>

But the Jscript associated with the date/time picker field has statements like:

document.EntryForm['yearEntry'].value = parseInt(vYear);

The missmatch seems just to be the Form name. In reality the problem is not so superficial - the standard behaviour of Date and Date/Time fields is designed round field in the main user interface and not for the 'Web to Lead' form. But we can work round this.

If you simply do a find and replace to rename the form 'EntryForm', it leads to a variety of errors, beginning with 'document.EntryForm.yearEntry is null or not an object' which turns into other errors as you may try and 'correct' the generated code.

You may end up with errors on submission such as

"Access violation at address 1A769778 in module 'eware.dll'. Read of address 00000015"

To correct the code we need to first simply the way in which the data is entered. Below shows some code that illustrates the manual rebuild of date and date/time fields.

<TD  VALIGN=TOP ><SPAN ID=_Captlead_rateddate class=VIEWBOXCAPTION>lead_rateddate:</SPAN>
<BR><SPAN ID=_Datalead_rateddate class=VIEWBOX ><input type="text" CLASS=EDIT ID="lead_rateddate" name="lead_rateddate"  value="" maxlength=40><input type=hidden name=_HIDDENlead_rateddate value=""><span CLASS=VIEWBOXNOBG><font color="blue" >*</font></span></SPAN>
<TD  VALIGN=TOP ><SPAN ID=_Captlead_createddate class=VIEWBOXCAPTION>lead_createddate:</SPAN>
<BR><SPAN ID=_Datalead_createddate class=VIEWBOX ><input type="text" CLASS=EDIT ID="lead_createddate" name="lead_createddate"  value="" maxlength=40><input type=hidden name=_HIDDENlead_createddate value=""><span CLASS=VIEWBOXNOBG><font color="blue" >*</font></span></SPAN>


Note: If you include system date/time fields such as lead_createddate then these behave in very particular ways when data is submitted. For example, the lead_createddate is always set to the current date as the record is saved - this is part of the commit process, so you can't make the date save into the future or past no matter what is entered into the form.

Note: If a field like 'lead_rateddate' is changed from a date to date/time field then the date and time information can be entered in the format 30/09/2009 17:10. This saves successfully. Any multi-part field in the 'Web to Lead' form would have to concatenate both parts (Date and Time) and submit them via the unified field e.g. 'lead_rateddate' to save successfully.