Custom Controls

A custom control is defined by a PHP class. The class is the registered with the function WebTemplate::registerControlClass.  The PHP class needs to contain the functions:

When adding the form field, the custom control can be specified by putting control={Control Name} in the settings for the control

 

Example:

<?php
class SampleControl
{
  public static function getControlHTML($formFieldName, $attributeInfo, $value) {    
    $html = '';
    $html = '<input name="' . $formFieldName . '" size="1" value="' . htmlentities($value) . '"/>';

    return $html;

  }

  public static function getControlFormValue($formFieldName, $attributeInfo, $formValues)
  {
    return $formValues[$formFieldName];
  }
}

$GLOBALS["WT"]->registerControlClass("Sample", "SampleControl");

For this example, the Settings attribute for the form field with the Sample Control will be

control=Sample

wtCustomCheckRequiredField

If the control is for a required field, you can create a javascript function called wtCustomCheckReqiredField(theForm, field). This function needs to be included on the page where the form is displayed and should return true if the required field is populated or false if the required field is not. It shouldn't return anything if the function does not handle the field.

Example:

function wtCustomCheckRequiredField(theForm, field) {
  if(field == 'howManyPeopleAttending') {
    if($('#howManyPeopleAttendingparents').val() == '' && $('#howManyPeopleAttendingchildren').val() == '') {
      return false;
    }
    return true;
  }
}