$errors['name'] = 'Name is required.'; } //if (empty($_POST['dirName'])) // $errors['name'] = 'Name is required.'; // return a response =========================================================== // if there are any errors in our errors array, return a success boolean of false if (!empty($errors)) { // if there are items in our errors array, return those errors $data['success'] = false; $data['errors'] = $errors; } else { // if there are no errors process our form, then return a message // DO ALL YOUR FORM PROCESSING HERE createAtomicCategoryDir($dirName); createSidebarIncludeAndFile($dirName); writeNavItem($dirName); createAjaxIncludeAndFile($dirName); createPageIncludeFile($dirName); createPageTemplate($dirName); createCompCatDir($dirName); createScssCatDirAndFile($dirName); createStringForMainScssFile($dirName); // show a message of success and provide a true success variable $data['success'] = true; $data['message'] = 'Success!'; } // return all our data to an AJAX call echo json_encode($data); ?>
<?php require '../temp-functions/functions.php'; require "../fllat.php"; $catdb = new Fllat("categories", "../../atomic-db"); $config = getConfig('../..'); $stylesDir = $config[0]['styles_directory']; $compDir = $config[0]['component_directory']; $errors = array(); $data = array(); $catName = test_input($_POST["catName"]); $filename = '../../' . $compDir . '/' . $catName . ''; $scssFilePath = '../../' . $stylesDir . '/' . $catName . ''; if (file_exists($filename) || file_exists($scssFilePath) && $catName != "") { $errors['exists'] = 'The category ' . $catName . ' already exists.'; } if ($_POST['catName'] == "") { $errors['name'] = 'Input is required.'; } if (!empty($errors)) { $data['success'] = false; $data['errors'] = $errors; } else { addCatDbItem($catName, $catdb); createScssCatDirAndFile($catName); createStringForMainScssFile($catName); createCompCatDir($catName); $data['success'] = true; $data['message'] = 'Success!'; } echo json_encode($data);