Skip to content

Commit

Permalink
form view option, check displayed in templates before using validatio…
Browse files Browse the repository at this point in the history
…n rules on submission
  • Loading branch information
Neil Jennings committed Jun 26, 2019
1 parent ac0bea9 commit 6ce374f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Libraries/Blocks/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use CoasterCms\Helpers\Cms\Email;
use CoasterCms\Helpers\Cms\View\FormWrap;
use CoasterCms\Facades\FormMessage;
use Illuminate\Support\Facades\Cache;
use PageBuilder;
use CoasterCms\Models\Block;
use CoasterCms\Models\BlockFormRule;
Expand All @@ -22,6 +23,11 @@ class Form extends AbstractBlock
*/
public static $blockSettings = ['Manage form input validation rules' => 'themes/forms'];

/**
* @var string
*/
protected $_displayedTemplatesKey;

/**
* Repeater constructor.
* @param Block $block
Expand All @@ -30,6 +36,7 @@ public function __construct(Block $block)
{
parent::__construct($block);
$this->_displayViewDirs[] = 'forms';
$this->_displayedTemplatesKey = 'displayed_form_' . $this->_block->id . '_templates';
}

/**
Expand All @@ -42,6 +49,12 @@ public function display($content, $options = [])
{
$formData = $this->_defaultData($content);
$view = !empty($options['view']) ? $options['view'] : $formData->template;
if ($view) {
$formTemplates = Cache::get($this->_displayedTemplatesKey, []);
$formTemplates[] = $view;
$formTemplates = array_unique($formTemplates);
Cache::put($this->_displayedTemplatesKey, $formTemplates, 60 + abs((int)config('coaster::frontend.cache')));
}
return FormWrap::view($this->_block, $options, $this->displayView($view), ['form_data' => $formData]);
}

Expand Down Expand Up @@ -98,7 +111,10 @@ public function submission($formData)
$form_settings = $this->_defaultData($form_settings);

if (!empty($formData['form_template'])) {
$form_settings->template = $formData['form_template'];
$formTemplates = Cache::get($this->_displayedTemplatesKey, []);
if (in_array($formData['form_template'], $formTemplates)) {
$form_settings->template = $formData['form_template'];
}
}

unset($formData['form_template']);
Expand Down

0 comments on commit 6ce374f

Please sign in to comment.