/** * Validates submitted form data. */ public function validate($aInput, $aOriginal, $oFactory) { // Formats the options $_oCategoryUnitOption = new AmazonAutoLinks_UnitOption_category(null, $aInput); $_aFormatted = $_oCategoryUnitOption->get(); // Drop unsent keys. foreach ($_aFormatted as $_sKey => $_mValue) { if (!array_key_exists($_sKey, $aInput)) { unset($_aFormatted[$_sKey]); } } // Schedule pre-fetch for the unit if the options have been changed. if ($aInput !== $aOriginal) { AmazonAutoLinks_Event_Scheduler::prefetch(AmazonAutoLinks_PluginUtility::getCurrentPostID()); } return $_aFormatted + $aInput; }
/** * Validates the submitted form data. * * @since 3 */ public function validateTabForm($aInput, $aOldInput, $oAdminPage, $aSubmitInfo) { $_bVerified = true; $_aErrors = array(); $aInput['associate_id'] = trim($aInput['associate_id']); if (empty($aInput['associate_id'])) { $_aErrors['associate_id'] = __('The associate ID cannot be empty.', 'amazon-auto-links'); $_bVerified = false; } // Evacuate some extra field items. $_aInputTemp = $aInput; // Format the unit options - this will also drop unnecessary keys for units. $_oUnitOptions = new AmazonAutoLinks_UnitOption_category(null, $aInput); $aInput = $_oUnitOptions->get() + $_aInputTemp; // An invalid value is found. Set a field error array and an admin notice and return the old values. if (!$_bVerified) { $oAdminPage->setFieldErrors($_aErrors); $oAdminPage->setSettingNotice(__('There was something wrong with your input.', 'amazon-auto-links')); return $aInput; } return $aInput; }
/** * Called when the user submits the form of the category select page. * @return array */ private function _getCategorySelectFormInput(array $aPost, $aInput, $oFactory) { // If the 'Save' or 'Create' button is pressed, save the data to the post. // The key is set in `AmazonAutoLinks_Form_CategorySelect` when rendering the form. if (isset($aPost['save'])) { $_oUnit = new AmazonAutoLinks_UnitOption_category(isset($_GET['post']) ? $_GET['post'] : null, $aInput); $_iPostID = $this->_postUnitByCategory($_oUnit->get(), $aInput); if ($_iPostID) { $oFactory->setSettingNotice(__('A unit has been created.', 'amazon-auto=links'), 'updated'); } $_oUtil = new AmazonAutoLinks_PluginUtility(); // Clean temporary options. $_oUtil->deleteTransient($GLOBALS['aal_transient_id']); // Schedule pre-fetch. AmazonAutoLinks_Event_Scheduler::prefetch($_iPostID); // Will exit the script. $_oUtil->goToPostDefinitionPage($_iPostID, AmazonAutoLinks_Registry::$aPostTypes['unit']); } // Otherwise, update the form data. return $this->_getUpdatedUnitOptions($aPost, $aInput, $oFactory); }