/**
  * See {@link \ValidFormBuilder\ValidForm::isValid()}
  * @see \ValidFormBuilder\ValidForm::isValid()
  */
 public function isValid($strPageId = null)
 {
     if (!is_null($strPageId)) {
         return $this->isValidUntil($strPageId);
     } else {
         return parent::isValid();
     }
 }
 public function buildForm($blnSend = true, $blnClientSide = true)
 {
     $objCms = PCMS_Client::getInstance();
     $strReturn = "";
     $this->__maxLengthAlert = $this->__formElement->getField("AlertMaxLength")->getHtmlValue();
     $this->__minLengthAlert = $this->__formElement->getField("AlertMinLength")->getHtmlValue();
     $this->__requiredAlert = $this->__formElement->getField("AlertRequired")->getHtmlValue();
     $this->__validForm->setRequiredStyle($this->__formElement->getField("RequiredIndicator")->getHtmlValue());
     $this->__validForm->setMainAlert($this->__formElement->getField("AlertMain")->getHtmlValue());
     //*** Form starts here.
     $objFieldsets = $this->__formElement->getElementsByTemplate(array("Fieldset", "Paragraph"));
     foreach ($objFieldsets as $objFieldset) {
         switch ($objFieldset->getTemplateName()) {
             case "Paragraph":
                 $this->renderParagraph($this->__validForm, $objFieldset);
                 break;
             case "Fieldset":
                 $this->renderFieldset($this->__validForm, $objFieldset);
                 $objFields = $objFieldset->getElementsByTemplate(array("Field", "Area", "ListField", "MultiField"));
                 foreach ($objFields as $objField) {
                     switch ($objField->getTemplateName()) {
                         case "Field":
                             $this->renderField($this->__validForm, $objField);
                             break;
                         case "ListField":
                             $this->renderListField($this->__validForm, $objField);
                             break;
                         case "Area":
                             $this->renderArea($this->__validForm, $objField);
                             break;
                         case "MultiField":
                             $this->renderMultiField($this->__validForm, $objField);
                             break;
                     }
                 }
         }
     }
     //*** Add conditions
     foreach ($objFieldsets as $objFieldset) {
         $this->addConditions($objFieldset);
         $objFields = $objFieldset->getElementsByTemplate(array("Field", "Area", "ListField", "MultiField"));
         foreach ($objFields as $objField) {
             $this->addConditions($objField);
         }
     }
     $this->__validForm->setSubmitLabel($this->__formElement->getField("SendLabel")->getHtmlValue());
     if ($this->__validForm->isSubmitted() && $this->__validForm->isValid()) {
         if ($blnSend) {
             $objRecipientEmails = $this->__formElement->getElementsByTemplate("RecipientEmail");
             foreach ($objRecipientEmails as $objRecipientEmail) {
                 $strHtmlBody = "<html><head><title></title></head><body>";
                 $strHtmlBody .= sprintf($objRecipientEmail->getField("Body")->getHtmlValue(), $this->__validForm->valuesAsHtml(true));
                 $strHtmlBody .= "</body></html>";
                 $varEmailId = $objRecipientEmail->getField("SenderEmail")->getValue();
                 $objEmailElement = $objCms->getElementById($varEmailId);
                 $strFrom = "webserver";
                 if (is_object($objEmailElement)) {
                     $varEmailId = $objEmailElement->getElement()->getApiName();
                     if (empty($varEmailId)) {
                         $varEmailId = $objEmailElement->getId();
                     }
                     $strFrom = $this->__validForm->getValidField("formfield_" . strtolower($varEmailId))->getValue();
                 }
                 $strErrors = $this->sendMail($objRecipientEmail->getField("Subject")->getHtmlValue(), $strHtmlBody, $strFrom, explode(",", $objRecipientEmail->getField("RecipientEmail")->getHtmlValue()));
                 if (!empty($strErrors)) {
                     throw new Exception($strErrors, E_ERROR);
                 }
             }
             $objSenderEmails = $this->__formElement->getElementsByTemplate("SenderEmail");
             foreach ($objSenderEmails as $objSenderEmail) {
                 $strHtmlBody = "<html><head><title></title></head><body>";
                 $strHtmlBody .= sprintf($objSenderEmail->getField("Body")->getHtmlValue(), $this->__validForm->valuesAsHtml(true));
                 $strHtmlBody .= "</body></html>";
                 $varEmailId = $objSenderEmail->getField("RecipientEmail")->getValue();
                 $objEmailElement = $objCms->getElementById($varEmailId);
                 if (is_object($objEmailElement)) {
                     $varEmailId = $objEmailElement->getElement()->getApiName();
                     if (empty($varEmailId)) {
                         $varEmailId = $objEmailElement->getId();
                     }
                 }
                 $strErrors = $this->sendMail($objSenderEmail->getField("Subject")->getHtmlValue(), $strHtmlBody, $objSenderEmail->getField("SenderEmail")->getHtmlValue(), array($this->__validForm->getValidField("formfield_" . strtolower($varEmailId))->getValue()));
                 if (!empty($strErrors)) {
                     throw new Exception($strErrors, E_ERROR);
                 }
             }
             $strReturn = $this->__formElement->getField("ThanksBody")->getHtmlValue();
         } else {
             $strReturn = $this->__formElement->getField("ThanksBody")->getHtmlValue();
         }
     } else {
         $strReturn = $this->__validForm->toHtml($blnClientSide);
     }
     return $strReturn;
 }