本文整理汇总了PHP中JForm::getErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP JForm::getErrors方法的具体用法?PHP JForm::getErrors怎么用?PHP JForm::getErrors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JForm
的用法示例。
在下文中一共展示了JForm::getErrors方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* 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;
}
示例2: validate
/**
* 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;
}
示例3: validate
/**
* 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;
}
示例4: validate
/**
* 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;
}
示例5: validateForm
/**
* 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;
}
示例6: validate
/**
* 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;
}
示例7: validate
/**
* 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;
}