Beispiel #1
0
 /**
  * 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;
 }
Beispiel #2
0
 /**
  * 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;
 }
 function onExtensionBeforeSave($context, $table, $isNew)
 {
     // *******************************
     // TODO: add support for com_menus
     // *******************************
     // Check for com_modules context
     if ($context == 'com_modules.module' || $context == 'com_advancedmodules.module' || substr($context, 0, 10) === "com_falang") {
         // Check for non-empty layout parameter
         $layout = $_POST['jform']['params']['layout'];
         if (empty($layout)) {
             return;
         }
         // Check for currently supported cases, !!! TODO add case of MENUS
         if (empty($table->module)) {
             return;
         }
         // Check if layout XML parameter file exists
         $client = JApplicationHelper::getClientInfo($table->client_id);
         $layoutpath = JPath::clean($client->path . '/modules/' . $table->module . '/tmpl/' . $layout . '.xml');
         if (!file_exists($layoutpath)) {
             $layoutpath = JPath::clean($client->path . '/modules/' . $table->module . '/tmpl/_fallback/_fallback.xml');
             if (!file_exists($layoutpath)) {
                 return;
             }
         }
         // Load XML file
         if (FLEXI_J30GE) {
             $xml = simplexml_load_file($layoutpath);
             $xmldoc =& $xml;
         } else {
             $xml = JFactory::getXMLParser('Simple');
             $xml->loadFile($layoutpath);
             $xmldoc =& $xml->document;
         }
         //echo "<pre>"; print_r($xmldoc); echo "</pre>";
         // Create form object loading the , (form name seems not to cause any problem)
         $jform = new JForm('com_flexicontent.template.item', array('control' => 'jform', 'load_data' => true));
         $tmpl_params = FLEXI_J30GE ? $xmldoc->asXML() : $xmldoc->toString();
         $jform->load($tmpl_params);
         // Set cleared layout parameters
         $_post =& $_POST['jform']['params'];
         //echo "<pre>"; print_r($_post); echo "</pre>";
         $params = new JRegistry($table->params);
         $grpname = 'params';
         $isValid = !$jform->validate($_post, $grpname);
         if ($isValid) {
             JFactory::getApplication()->enqueueMessage('Error validating layout posted parameters. Layout parameters were not saved', 'error');
             return;
         }
         foreach ($jform->getGroup($grpname) as $field) {
             $fieldname = $field->__get('fieldname');
             if (substr($fieldname, 0, 2) == "__") {
                 continue;
             }
             $value = $_post[$fieldname];
             $params->set($fieldname, $value);
         }
         // Set parameters back to module's DB table object
         $table->params = $params->toString();
         //echo "<pre>"; print_r($table->params); echo "</pre>";
         //die('onExtensionBeforeSave: '. $layoutpath);
     }
 }
Beispiel #4
0
 /**
  * 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;
 }
Beispiel #5
0
 /**
  * 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;
 }
Beispiel #8
0
 /**
  * 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;
 }