function validate() { $errors = array(); if (!$_POST["source"]) { return; } $shownotes = new Model\Shownotes(); $shownotes->source = $_POST["source"]; $shownotes->parse(); $shownotes->validate(); foreach ($shownotes->shownotes as $shownote) { if ($shownote->isValid) { continue; } $errors[] = array('line' => $shownote->line, 'type' => 'error', 'text' => $shownote->errorMessage); } Ajax::respond_with_json($errors); }