/** * Method to validate the form data. * Each field error is stored in session and can be retrieved with getFieldError(). * Once getFieldError() is called, the error is deleted from the session. * * @param JForm $form The form to validate against. * @param array $data The data to validate. * @param string $group The name of the field group to validate. * * @return mixed Array of filtered data if valid, false otherwise. */ public function validate($form, $data, $group = null) { // Filter and validate the form data. $data = $form->filter($data); $return = $form->validate($data, $group); // Check for an error. if ($return instanceof Exception) { $this->setError($return->getMessage()); return false; } // Check the validation results. if ($return === false) { $session = JFactory::getSession(); // Get the validation messages from the form. foreach ($form->getErrors() as $key => $message) { $this->setError($message); if ($message instanceof Exception) { // Store the field error in session. $session->set($this->context . '.error.' . $key, $message->getMessage()); } else { // Store the field error in session. $session->set($this->context . '.error.' . $key, $message); } } return false; } return $data; }
/** * Method to validate the form data. * * @param JForm $form The form to validate against. * @param array $data The data to validate. * @param string $group The name of the field group to validate. * * @return mixed Array of filtered data if valid, false otherwise. * * @see JFormRule * @see JFilterInput * @since 12.2 */ public function validate($form, $data, $group = null) { // Filter and validate the form data. $data = $form->filter($data); $return = $form->validate($data, $group); // Check for an error. if ($return instanceof Exception) { $this->setError($return->getMessage()); return false; } // Check the validation results. if ($return === false) { // Get the validation messages from the form. foreach ($form->getErrors() as $message) { $this->setError($message); } return false; } return $data; }
/** * Method to validate the form data. * * @param JForm $form The form to validate against. * @param array $data The data to validate. * @param string $group The name of the field group to validate. * * @return array|boolean Array of filtered data if valid, false otherwise. * * @see JFormRule * @see JFilterInput * @since 12.2 */ public function validate($form, $data, $group = null) { // Include the plugins for the delete events. JPluginHelper::importPlugin($this->events_map['validate']); $dispatcher = JEventDispatcher::getInstance(); $dispatcher->trigger('onUserBeforeDataValidation', array($form, &$data)); // Filter and validate the form data. $data = $form->filter($data); $return = $form->validate($data, $group); // Check for an error. if ($return instanceof Exception) { $this->setError($return->getMessage()); return false; } // Check the validation results. if ($return === false) { // Get the validation messages from the form. foreach ($form->getErrors() as $message) { $this->setError($message); } return false; } // Tags B/C break at 3.1.2 if (isset($data['metadata']['tags']) && !isset($data['tags'])) { $data['tags'] = $data['metadata']['tags']; } return $data; }
/** * Method to validate the form data. * * @param JForm $form The form to validate against. * @param array $data The data to validate. * @param string $group The name of the field group to validate. * * @return mixed Array of filtered data if valid, false otherwise. * * @see JFormRule * @see JFilterInput * @since 3.2 */ public function validate($form, $data, $group = null) { // Filter and validate the form data. $data = $form->filter($data); $return = $form->validate($data, $group); // Check for an error. if ($return instanceof Exception) { JFactory::getApplication()->enqueueMessage($return->getMessage(), 'error'); return false; } // Check the validation results. if ($return === false) { // Get the validation messages from the form. foreach ($form->getErrors() as $message) { if ($message instanceof Exception) { $message = $message->getMessage(); } JFactory::getApplication()->enqueueMessage($message, 'error'); } return false; } return $data; }
/** * Method to validate the permissions form data. * * @param \JForm $form The form to validate against. * @param array $data The data to validate. * @param string $group The name of the field group to validate. * @return array|string Array of filtered data if valid, string with error otherwise. */ protected static function validateForm( $form, $data, $group = null ) { $data = $form->filter( $data ); $return = $form->validate( $data, $group ); if ( $return instanceof \Exception ) { /** @var $return \Exception */ return $return->getMessage(); } if ( $return === false ) { $errors = array(); foreach ( $form->getErrors() as $message ) { $errors[] = \JText::_($message); } return implode( "\n", $errors ); } return $data; }
/** * Method to validate the form data. * * @param \JForm $form The form to validate against. * @param array $data The data to validate. * @param string $group The name of the field group to validate. * * @throws ValidateFailException * @throws \Exception * @return mixed Array of filtered data if valid, false otherwise. * * @see JFormRule * @see JFilterInput */ public function validate($form, $data, $group = null) { // Filter and validate the form data. /** @var $form \JForm */ $data = $form->filter($data); $return = $form->validate($data, $group); // Check for an error. if ($return instanceof \Exception) { throw $return; } // Check the validation results. if ($return === false) { // Get the validation messages from the form. throw new ValidateFailException($form->getErrors()); } return $data; }
/** * Method to validate the form data. * * @param JForm $form The form to validate against. * @param array $data The data to validate. * @param string $group The name of the field group to validate. * * @return mixed Array of filtered data if valid, false otherwise. * * @see JFormRule * @see JFilterInput * @since 12.2 */ public function validate($form, $data, $group = null) { // Filter and validate the form data. $data = $form->filter($data); $return = $form->validate($data, $group); // Check for an error. if ($return instanceof Exception) { $this->setError($return->getMessage()); return false; } // Check the validation results. if ($return === false) { // Get the validation messages from the form. foreach ($form->getErrors() as $message) { $this->setError($message); } return false; } $config = JFactory::getConfig(); $tzoffset = $config->get('offset'); if (isset($data['order_date']) && $data['order_date']) { $date = JFactory::getDate($data['order_date']); $purchase_date = $date->toSql(); $order_date = $date->toUNIX(); } else { $purchase_date = date('Y-m-d H:i:s', time() + $tzoffset); $date = JFactory::getDate(); $order_date = $date->toUNIX(); } $data['order_date'] = $order_date; $data['promocodediscount'] = $data['discount']; $data['promocodeid'] = $this->getPromocodeByCode($data['discount']); $data['number_of_products'] = count($data['product_id']); $data['published'] = '1'; return $data; }