Support success and error callbacks in rx_ajax submissions using iframe

This commit is contained in:
Kijin Sung 2021-09-13 10:57:55 +09:00
parent f3918d792a
commit 1f1e01917e
2 changed files with 19 additions and 13 deletions

View file

@ -972,24 +972,21 @@ class ModuleHandler extends Handler
// Handle iframe form submissions.
if(isset($_POST['_rx_ajax_form']) && starts_with('_rx_temp_iframe_', $_POST['_rx_ajax_form']))
{
$script = '';
if(!$oModule->toBool())
$data = [];
if ($this->error)
{
$script .= sprintf('window.parent.alert(%s);', json_encode($oModule->getMessage()));
$data['error'] = -1;
$data['message'] = lang($this->error);
}
else
{
if($oModule->getMessage() && $oModule->getMessage() !== 'success')
{
$script .= sprintf('window.parent.rhymix_alert(%s, %s);', json_encode($oModule->getMessage()), json_encode($oModule->getRedirectUrl()));
}
if($oModule->getRedirectUrl())
{
$script .= sprintf('window.parent.redirect(%s);', json_encode($oModule->getRedirectUrl()));
}
$data['error'] = $oModule->error;
$data['message'] = lang($oModule->message);
}
$data = array_merge($data, $oModule->getVariables());
ob_end_clean();
echo sprintf('<html><head></head><body><script>%s window.parent.remove_iframe(%s);</script></body></html>', $script, json_encode($_POST['_rx_ajax_form']));
echo sprintf('<html><head></head><body><script>parent.XE.handleIframeResponse(%s, %s);</script></body></html>', json_encode(strval($_POST['_rx_ajax_form'])), json_encode($data));
return;
}