customer_id = $customer->id; $template->json = file_get_contents("json/default_template.json"); $submit = http::value("submit"); if($submit) { try { Core::validateCSRFToken($submit); $form_exception = new FormException; $template->name = http::value("name", "trim"); $template->json = http::value("json", "trim"); if(empty($template->name)) $form_exception->addError("Name is required."); if(empty($template->json)) $form_exception->addError("JSON is required."); $json = json_decode($template->json); if(!$json) { $form_exception->addError("JSON error: " . json_last_error_msg()); } if($form_exception->hasErrors()) throw $form_exception; $success = $template->commit(); Core::addAlert("success", "Template added successfully."); HTTP::redirect("/account/templates?customer_id=$customer->id"); } catch(FormException $e) { $e->generateAlerts(); } catch(Exception $e) { Core::addAlert("danger", $e->getMessage()); } } View::includeOnce("header", compact("page_title")); View::include("template_add_form", compact("template")); View::includeOnce("footer"); ?>