Creating a custom form handler

In the template, specify the form to display and create an action to take when the form is submitted:
 

<wt:form source="Contact Us Consumer" action="contactSubmit"/>

In a PHP file in the code folder, declare a function to process the form and then register the form handler:
 

class ContactUs {
  /**
   * This function will process contact us form submissions
   *
   *
   **/

  public static function processContactForm($action, $data) {
    // $action should be set to contactSubmit,
    // $action is passed in so you can use the same function to process multiple forms

    // get the guid of the form which was submitted
    $formGuid = (int)$GLOBALS["WT"]->getRequestValue("formGuid", 0);
    if ($formGuid) {
      // get the form object
      $formNode = $GLOBALS["WT"]->getNode($formGuid);
      if ($formNode && $formNode->m_typeName == "wtForm") {
        // get the form data with labels rather than internal WebTemplate names
        $data = $formNode->getFormDataFromRequest(true);

        // now for example, create a contact with the form data
        $attributes = Array();
        $attributes["First Name"] = $data["First Name"];
        $attributes["Last Name"] = $data["Last Name"];
        $attributes["Email Address"] = $data["Email Address"];

        $contacts = $GLOBALS["WT"]->getNode("/Contacts");
        $contact = $contacts->createChild("Contact", $attributes);

        // return the contact (non false value) to show the form was processed
      }
    }

    // error processing the form, return false to indicate the form wasn't processed
    return false;
  }
}

WTForm::registerFormHandler("contactSubmit", Array("ContactUs", "processContactForm"));