public function getForm() { $strMaxLength = "Your input is too long. Maximum length is %s"; $strMinLength = "Your input is too short. Minimum length is %s"; $strRequired = "This field is required."; $objForm = new ValidForm("installForm"); $objForm->setMainAlert("One or more errors occured. Check the marked fields and try again."); $objForm->addFieldset("CMS type", NULL, "PunchCMS can be installed for a single website or multiple websites at once."); $objForm->addField("single_instance", "Single website", VFORM_BOOLEAN); $objForm->addFieldset("Administrator settings", NULL, "This is the account for the admin area. Later you can create an admin per website."); $objForm->addField("username", "Username", VFORM_STRING, array("maxLength" => 255, "required" => true), array("maxLength" => $strMaxLength, "required" => $strRequired, "type" => "Enter only letters and spaces.")); $objForm->addField("passwd", "Password", VFORM_PASSWORD, array("maxLength" => 255, "required" => true), array("maxLength" => $strMaxLength, "required" => $strRequired, "type" => "Enter only letters and numbers.")); $objForm->addField("email", "Email address", VFORM_EMAIL, array("maxLength" => 32, "required" => true), array("maxLength" => $strMaxLength, "required" => $strRequired, "type" => "Use the format name@domain.extension."), array("tip" => "This address will be used as the sender address for password reminders.")); $objForm->addFieldset("MySQL settings", NULL, "The database and user must already exist, otherwise the installation will fail."); $objForm->addField("db_server", "Server address", VFORM_STRING, array("maxLength" => 255, "required" => true), array("maxLength" => $strMaxLength, "required" => $strRequired, "type" => "Enter the address of the MySQL server."), array("default" => "localhost")); $objForm->addField("db_name", "Database name", VFORM_STRING, array("maxLength" => 255, "required" => true), array("maxLength" => $strMaxLength, "required" => $strRequired, "type" => "Enter the name of the designated database."), array("default" => "punchcms")); $objForm->addField("db_username", "Username", VFORM_STRING, array("maxLength" => 255, "required" => true), array("maxLength" => $strMaxLength, "required" => $strRequired, "type" => "Enter the username for the database.")); $objForm->addField("db_passwd", "Password", VFORM_PASSWORD, array("maxLength" => 32, "required" => false), array("maxLength" => $strMaxLength, "type" => "Enter the password for the database.")); $objForm->setSubmitLabel("Submit"); return $objForm; }
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; }