Formal\Form::declareError PHP Method

declareError() public method

# public, as it may be called from a hook
public declareError ( Element $oElement, $sMessage = "" )
$oElement Element
    function declareError(\Formal\Element $oElement, $sMessage = "")
    {
        $this->aErrors[] = ["element" => $oElement, "message" => $sMessage];
        $oElement->setOption("error", true);
    }

Usage Example

Example #1
0
 public function validationHook(\Formal\Form $oForm, \Formal\Form\Morphology $oMorpho)
 {
     if (intval($oForm->modelInstance()->get("PROJECT_DB_MYSQL")) === 1) {
         # We have to check the MySQL connection
         $sHost = $oForm->modelInstance()->get("PROJECT_DB_MYSQL_HOST");
         $sDbName = $oForm->modelInstance()->get("PROJECT_DB_MYSQL_DBNAME");
         $sUsername = $oForm->modelInstance()->get("PROJECT_DB_MYSQL_USERNAME");
         $sPassword = $oForm->modelInstance()->get("PROJECT_DB_MYSQL_PASSWORD");
         try {
             $oDB = new \Flake\Core\Database\Mysql($sHost, $sDbName, $sUsername, $sPassword);
         } catch (\Exception $e) {
             $sMessage = "<strong>MySQL error:</strong> " . $e->getMessage();
             $sMessage .= "<br /><strong>Nothing has been saved</strong>";
             $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_HOST"), $sMessage);
             $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_DBNAME"));
             $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_USERNAME"));
             $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_PASSWORD"));
             return;
         }
         if (($aMissingTables = \Baikal\Core\Tools::isDBStructurallyComplete($oDB)) !== TRUE) {
             $sMessage = "<strong>MySQL error:</strong> These tables, required by Baïkal, are missing: <strong>" . implode(", ", $aMissingTables) . "</strong><br />";
             $sMessage .= "You may want create these tables using the file <strong>Core/Resources/Db/MySQL/db.sql</strong>";
             $sMessage .= "<br /><br /><strong>Nothing has been saved</strong>";
             $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL"), $sMessage);
             return;
         }
     }
 }
All Usage Examples Of Formal\Form::declareError