/** * Handles doing quiz and survey insertions into * the database. Starts of creating the form object * using either Wpsqt_Form_Quiz or Wpsqt_Form_Survey * then it moves on to check and see if * * * @since 2.0 */ protected function _doInsert() { $className = "Wpsqt_Form_" . ucfirst($this->_subsection); $objForm = new $className(); $this->_pageVars = array('objForm' => $objForm, 'objTokens' => Wpsqt_Tokens::getTokenObject()); if ($_SERVER['REQUEST_METHOD'] == "POST") { $errorMessages = $objForm->getMessages($_POST); $details = $_POST; unset($details['wpsqt_nonce']); if (empty($errorMessages)) { $details = Wpsqt_Form::getSavableArray($details); $this->_pageVars['id'] = Wpsqt_System::insertItemDetails($details, strtolower($this->_subsection)); do_action('wpsqt_' . strtolower($this->_subsection) . '_addnew'); $this->_pageView = "admin/misc/redirect.php"; $this->_pageVars['redirectLocation'] = WPSQT_URL_MAIN . "§ion=sections&subsection=" . strtolower($this->_subsection) . "&id=" . $this->_pageVars['id'] . "&new=1"; } else { $objForm->setValues($details); $this->_pageVars['errorArray'] = $errorMessages; } } }
/** * Handles the doing updating of quiz and surveys. * Firstly it gets the quiz or survey details using * either getQuizDetails or getSurveyDetails. Then * creates the page form using either Wpsqt_Form_Quiz * or Wpsqt_Form_Survey. Then it checks to see if it's * a post request if so it then checks to see if it * assigns $_POST as the details for the quiz or survey. * At which point it does a validation call to see if * there are any error messages if not it does an update * call using either Wpsqt_System::updateQuizDetails or * Wpsqt_System::updateSurveyDetails. * * Uses $this->_subsection to find out if it's to use * Quiz or Survey functions. * * @since 2.0 */ protected function _doUpdate() { $this->_pageView = "admin/quiz/create.php"; $details = Wpsqt_Form::getInsertableArray(Wpsqt_System::getItemDetails($_GET['id'], strtolower($this->_subsection))); $className = "Wpsqt_Form_" . ucfirst($this->_subsection); $objForm = new $className(); $this->_pageVars = array('objForm' => $objForm, 'objTokens' => Wpsqt_Tokens::getTokenObject()); if ($_SERVER['REQUEST_METHOD'] == "POST" && !isset($_POST['new-page'])) { $errorMessages = $objForm->getMessages($_POST); $details = $_POST; $details['wpsqt_id'] = $_GET['id']; unset($details['wpsqt_nonce']); if (empty($errorMessages)) { Wpsqt_System::updateItemDetails(Wpsqt_Form::getSavableArray($details), $_GET['subsection']); do_action('wpsqt_' . strtolower($this->_subsection) . '_edit'); $this->_pageVars['successMessage'] = ucfirst($this->_subsection) . " updated!"; } else { $this->_pageVars['errorArray'] = $errorMessages; } } $objForm->setValues($details); }
/** * Check to make sure the form select elements * are validating properly. * * @since 2.0 */ public function testFormSelectValidation() { $objForm = new Wpsqt_Form(); $objForm->addOption("wpsqt_test", "Test", "select", false, "None", array("one", "two", "three")); $errorMessages = $objForm->getMessages(array()); $this->assertEquals(array("Test can't be empty."), $errorMessages, "Invalid error message given for no value."); $errorMessages = $objForm->getMessages(array("wpsqt_test" => "")); $this->assertEquals(array("Test can't be empty."), $errorMessages, "Invalid error message given for empty value."); $errorMessages = $objForm->getMessages(array("wpsqt_test" => "none")); $this->assertEquals(array("Test doesn't have a valid response."), $errorMessages, "Invalid error message given for invalid response."); }