Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/Extension/EditableFormField_InitialVisibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace DNADesign\UserFormExtras\Extension;

use SilverStripe\Core\Extension;
use SilverStripe\Control\Session;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Core\Injector\Injector;

class EditableFormField_InitialVisibility extends Extension
{
Expand All @@ -21,9 +22,11 @@ public function afterUpdateFormField(&$field)

foreach ($rules as $rule) {
$conditionFieldName = $rule->ConditionField()->Name;
// Can only get the data from the session
// Has we may get redirected at this stage and the request will be empty
$value = Session::get('FormInfo.BetterUserForm_Form.data.'.$conditionFieldName);

// Applying fix provided @Ashpik https://github.com/dnadesign/userforms-extra/issues/2
$request = Injector::inst()->get(HTTPRequest::class);
$session = $request->getSession();
$value = $session->get('FormInfo.BetterUserForm_Form.data.' . $conditionFieldName);

// If field has a rules that would reveal it
if ($rule->Display == 'Show' && $value) {
Expand Down