Skip to content

Commit

Permalink
Fix issue Form does not work at #868
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Nov 15, 2024
1 parent 61a300f commit 0a0433a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
13 changes: 8 additions & 5 deletions framework/elements/formbuilder/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@
use Astroid\Helper;

$mainframe = Factory::getApplication();
$asformbuilder = $mainframe->input->get('as-form-builder-', array(), 'RAW');
$unqid = $mainframe->input->get('form_id', '', 'ALNUM');
$element = Helper::getElement($unqid);
$asformbuilder = $mainframe->input->post->get('as-form-builder-', array(), 'RAW');
$unqid = $mainframe->input->post->get('form_id', '', 'string');
$source = $mainframe->input->post->get('source', '', 'string');
$template = $mainframe->input->post->get('template', '', 'string');
$layout_type = $mainframe->input->post->get('layout_type', '', 'string');
$element = Helper::getElement($unqid, '', ['source' => $source, 'template' => $template, 'layout_type' => $layout_type]);
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
$return = array();
try {
if (!empty($asformbuilder)) {
if (empty($asformbuilder)) {
throw new \Exception(Text::_('ASTROID_AJAX_ERROR_INVALID_FORM_DATA'));
}
if (!empty($element)) {
if (empty($element)) {
throw new \Exception(Text::_('ASTROID_AJAX_ERROR_INVALID_FORM_ID'));
}
$params = $element['params'];
Expand Down
10 changes: 9 additions & 1 deletion framework/elements/formbuilder/formbuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
if (empty($form_elements) || !count($form_elements)) {
return false;
}

$row_column_cls = '';
$responsive_key = ['xxl', 'xl', 'lg', 'md', 'sm', 'xs'];
foreach ($responsive_key as $key) {
Expand Down Expand Up @@ -158,6 +157,15 @@
echo '<input type="hidden" name="form_id" value="'.$element->unqid.'">';
echo '<input type="hidden" name="template" value="'.Astroid\Framework::getTemplate()->id.'">';
echo '<input type="hidden" name="widget" value="formbuilder">';
if (isset($options['source']) && $options['source']) {
echo '<input type="hidden" name="source" value="'.$options['source'].'">';
}
if (isset($options['template']) && $options['template']) {
echo '<input type="hidden" name="template" value="'.$options['template'].'">';
}
if (isset($options['layout_type']) && $options['layout_type']) {
echo '<input type="hidden" name="layout_type" value="'.$options['layout_type'].'">';
}
echo '<input type="hidden" class="token" name="'.Session::getFormToken().'" value="1">';

$button_style = $params->get('button_style', 'primary');
Expand Down
4 changes: 3 additions & 1 deletion framework/library/astroid/Element/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public static function renderSublayout($source, $template = '', $type = 'layouts
'title'=> 'title'
]
];
$options['layout_type'] = 'sublayout';
$options['layout_type'] = $type;
$options['source'] = $source;
$options['template'] = !empty($template) ? $template : Framework::getTemplate()->template;
$content = '';
foreach ($layout['sections'] as $section) {
$section = new Section($section, $devices, $options);
Expand Down
2 changes: 1 addition & 1 deletion framework/library/astroid/Element/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Section extends BaseElement

public function __construct($data, $devices, $options = array())
{
if (isset($options['layout_type']) && $options['layout_type'] == 'sublayout') {
if (isset($options['layout_type']) && ($options['layout_type'] == 'layouts' || $options['layout_type'] == 'article_layouts')) {
$this->_tag = 'div';
}
parent::__construct($data, $devices, $options);
Expand Down
14 changes: 12 additions & 2 deletions framework/library/astroid/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

namespace Astroid;
use Astroid\Element\Layout;
use Joomla\CMS\Cache\CacheControllerFactoryInterface;
use Joomla\CMS\Event\Cache\AfterPurgeEvent;
use Joomla\CMS\Factory;
Expand Down Expand Up @@ -402,11 +403,20 @@ public static function getAllAstroidElements($mode = '', $template_id = null)
return $return;
}

public static function getElement($unqid, $template = null) {
public static function getElement($unqid, $template = null, $options = []) {
if (empty($template)) {
$template = Framework::getTemplate();
}
$layout = $template->getLayout();
if (isset($options['source']) && !empty($options['source'])) {
$sublayout = Layout::getDataLayout($options['source'], (isset($options['template']) && !empty($options['template']) ? $options['template'] : ''), (isset($options['layout_type']) && !empty($options['layout_type']) ? $options['layout_type'] : 'layouts'));
if (!isset($sublayout['data']) || !$sublayout['data']) {
return false;
}
$layout = \json_decode($sublayout['data'], true);
} else {
$layout = $template->getLayout();
}

foreach ($layout['sections'] as $section) {
if ($section['id'] == $unqid) {
$section['params'] = self::loadParams($section['params']);
Expand Down

0 comments on commit 0a0433a

Please sign in to comment.