$bgColor = test_input($_POST["bgColor"]); $fileExists = '../../components/' . $compDir . '/' . $fileCreateName . '.' . $compExt . ''; if (file_exists($fileExists) && $fileCreateName != "") { $errors['exists'] = 'A file named ' . $fileCreateName . ' already exists.'; } elseif ($_POST['fileCreateName'] == "") { $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 createScssFile($compDir, $fileCreateName); writeScssImportFile($compDir, $fileCreateName); createCompFile($compDir, $fileCreateName); createIncludeString($compDir, $compNotes, $fileCreateName, $bgColor); createAjaxIncludeAndCompFile($compDir, $fileCreateName); // 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); ?>
$jsDir = $config[0]['js_directory']; $jsExt = $config[0]['js_extension']; $filename = '../../' . $compDir . '/' . $catName . '/' . $compName . '.' . $compExt . ''; $scssFilePath = '../../' . $stylesDir . '/' . $catName . '/_' . $compName . '.' . $stylesExt . ''; if (file_exists($filename) || file_exists($scssFilePath) && $catName != "") { $errors['exists'] = 'The component ' . $compName . ' already exists.'; } if ($_POST['compName'] == "") { $errors['name'] = 'Component 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 ($js_file == "true") { createJsFile($compName, $jsDir, $jsExt); createJsComment($compName); } addCompDbItem($compName, $catName, $compNotes, $bgColor, $js_file, $compdb); createCompFile($catName, $compName); createCompComment($catName, $compName); createStylesFile($catName, $compName); createStyleComment($catName, $compName); writeStylesImport($catName, $compName); $data['success'] = true; $data['message'] = 'Success!'; } echo json_encode($data);