[Vtigercrm-developers] Designing portable Webforms with custom fields capture.

Prasad prasad at vtiger.com
Fri Sep 23 07:50:10 PDT 2011


Hi,

Today our support team posed a challenge to design webform for capturing
Leads with the following ability:

   1. Leads module has custom fields that needs to be taken care.
   2. The webform should be portable across vtiger CRM instances.

With existing Webforms module (post.php) Requirement 1, was sort of easy to
be handled.
However, Requirement 2 was hard to meet in current design.

The limitation was Weforms/post.php allowed only "fieldname" of module,
which (could) change for custom field on every setup!

We extended webforms_getUserData API (in modules/Webforms/post.php - see
attachment) to adress both the requirements.

This enables webform designer to specify the form element name as:
"fieldname" or "label:fieldlabel"

For standard fields, use of "fieldname" will continue to work and for custom
fields,
use of "label:fieldlabel" will be handy to that can work across different
setups
as long as the fieldlabel are consistently used (irrespective of dynamic
fieldname).

Regards,
Prasad
vtiger Team

*Connect with us on: *Twitter <http://twitter.com/#!/vtigercrm> *I*
Facebook<http://www.facebook.com/pages/vtiger/226866697333578?sk=wall>
 *I* Blog <http://blog.vtiger.com/>* I*
Wiki<http://wiki.vtiger.com/index.php/Main_Page>
 *I *Forums  <http://forums.vtiger.com/>*I* Website <http://vtiger.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20110923/cffde3df/attachment-0002.html 
-------------- next part --------------
function webforms_getUserData($ownerId,$describeFields,$source){
	$userData = Array();
	
	for($i = 0, $len = sizeof($describeFields);$i<$len;++$i){
		$fieldName = $describeFields[$i]['name'];
		
		// Handle meta fields right away
		if ($describeFields[$i]['type']['name'] == 'owner') {
			$userData[$fieldName] = $ownerId;
			continue;
		}
		/* TODO: if($describeFields[$i]['type']['name'] == 'reference'){ continue; }*/
		
		/**
		 * Support for specifying (fieldname or label:fieldlabel)
		 */		

		// NOTE: Spaces in parameter key will be converted to _ 
		$transformedFieldLabel= str_replace(' ','_', $describeFields[$i]['label']);
								
		$valuekey = false;
		if (isset($source[$fieldName])) {
			$valuekey = $fieldName;
		} else if (isset($source["label:$transformedFieldLabel"])) {
			$valuekey = "label:$transformedFieldLabel";
		}
				
		if($valuekey) {
			$value = vtws_getParameter($source, $valuekey);
			if($value !== null){
				$userData[$fieldName] = $value;
			}
		} else if($describeFields[$i]['mandatory'] == true) {
			return null;
		}
	}
	return $userData;
}


More information about the vtigercrm-developers mailing list