Skip to content

Commit

Permalink
Merge branch 'joomla3' of github.com:Fabrik/fabrik into joomla3
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesegrits committed Feb 28, 2014
2 parents a4af5e6 + 5f0d5f2 commit 41404fe
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 69 deletions.
158 changes: 90 additions & 68 deletions administrator/components/com_fabrik/controllers/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,74 +139,9 @@ public function process()

if (!$validated)
{
// If its in a module with ajax or in a package or inline edit
if ($input->get('fabrik_ajax'))
{
if ($input->getInt('elid') !== 0)
{
// Inline edit
$eMsgs = array();
$errs = $model->getErrors();

// Only raise errors for fields that are present in the inline edit plugin
$toValidate = array_keys($input->get('toValidate', array(), 'array'));

foreach ($errs as $errorKey => $e)
{
if (in_array($errorKey, $toValidate) && count($e[0]) > 0)
{
array_walk_recursive($e, array('FabrikString', 'forHtml'));
$eMsgs[] = count($e[0]) === 1 ? '<li>' . $e[0][0] . '</li>' : '<ul><li>' . implode('</li><li>', $e[0]) . '</ul>';
}
}

if (!empty($eMsgs))
{
$eMsgs = '<ul>' . implode('</li><li>', $eMsgs) . '</ul>';
header('HTTP/1.1 500 ' . FText::_('COM_FABRIK_FAILED_VALIDATION') . $eMsgs);
jexit();
}
else
{
$validated = true;
}
}
else
{
echo $model->getJsonErrors();
}

if (!$validated)
{
return;
}
}

if (!$validated)
{
$this->savepage();
$this->handleError($view, $model);

if ($this->isMambot)
{
$input->set('fabrik_referrer', JArrayHelper::getValue($_SERVER, 'HTTP_REFERER', ''), 'post');
}
else
{
/**
* $$$ rob - http://fabrikar.com/forums/showthread.php?t=17962
* couldn't determine the exact set up that triggered this, but we need to reset the rowid to -1
* if reshowing the form, otherwise it may not be editable, but rather show as a detailed view
*/
if ($input->get('usekey') !== '')
{
$input->set('rowid', -1);
}

$view->display();
}

return;
}
return;
}

// Reset errors as validate() now returns ok validations as empty arrays
Expand All @@ -227,7 +162,7 @@ public function process()
if ($model->hasErrors())
{
FabrikWorker::getPluginManager()->runPlugins('onError', $model);
$view->display();
$this->handleError($view, $model);

return;
}
Expand Down Expand Up @@ -260,6 +195,93 @@ public function process()
}
}

/**
* Handle the view error
*
* @param JView $view View
* @param JModel $model Form Model
*
* @since 3.1b
*
* @return void
*/
protected function handleError($view, $model)
{
$app = JFactory::getApplication();
$package = $app->getUserState('com_fabrik.package', 'fabrik');
$input = $app->input;
$validated = false;

// If its in a module with ajax or in a package or inline edit
if ($input->get('fabrik_ajax'))
{
if ($input->getInt('elid') !== 0)
{
// Inline edit
$eMsgs = array();
$errs = $model->getErrors();

// Only raise errors for fields that are present in the inline edit plugin
$toValidate = array_keys($input->get('toValidate', array(), 'array'));

foreach ($errs as $errorKey => $e)
{
if (in_array($errorKey, $toValidate) && count($e[0]) > 0)
{
array_walk_recursive($e, array('FabrikString', 'forHtml'));
$eMsgs[] = count($e[0]) === 1 ? '<li>' . $e[0][0] . '</li>' : '<ul><li>' . implode('</li><li>', $e[0]) . '</ul>';
}
}

if (!empty($eMsgs))
{
$eMsgs = '<ul>' . implode('</li><li>', $eMsgs) . '</ul>';
header('HTTP/1.1 500 ' . FText::_('COM_FABRIK_FAILED_VALIDATION') . $eMsgs);
jexit();
}
else
{
$validated = true;
}
}
else
{
echo $model->getJsonErrors();
}

if (!$validated)
{
return;
}
}

if (!$validated)
{
$this->savepage();

if ($this->isMambot)
{
$this->setRedirect($this->getRedirectURL($model, false));
}
else
{
/**
* $$$ rob - http://fabrikar.com/forums/showthread.php?t=17962
* couldn't determine the exact set up that triggered this, but we need to reset the rowid to -1
* if reshowing the form, otherwise it may not be editable, but rather show as a detailed view
*/
if ($input->get('usekey') !== '')
{
$input->set('rowid', -1);
}

$view->display();
}

return;
}
}

/**
* Save a form's page to the session table
*
Expand Down
2 changes: 1 addition & 1 deletion components/com_fabrik/controllers/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public function process()
if ($model->hasErrors())
{
FabrikWorker::getPluginManager()->runPlugins('onError', $model);
$view->display();
$this->handleError($view, $model);

return;
}
Expand Down

0 comments on commit 41404fe

Please sign in to comment.