File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change 59
59
$ formanswer ->redirectToList ();
60
60
61
61
} else if (isset ($ _POST ['save_formanswer ' ])) {
62
- $ formanswer ->updateAnswers ($ _POST );
62
+ if (!$ formanswer ->updateAnswers ($ _POST )) {
63
+ Html::back ();
64
+ }
63
65
if (plugin_formcreator_replaceHelpdesk ()) {
64
66
$ issue = new PluginFormcreatorIssue ();
65
67
$ issue ->redirectToList ();
Original file line number Diff line number Diff line change @@ -848,10 +848,36 @@ public function updateAnswers($input) {
848
848
$ form ->getFromDB ((int ) $ input ['plugin_formcreator_forms_id ' ]);
849
849
$ input ['status ' ] = self ::STATUS_WAITING ;
850
850
851
+ $ valid = true ;
852
+ $ fieldValidities = [];
853
+
851
854
$ fields = $ form ->getFields ();
852
855
foreach ($ fields as $ id => $ question ) {
853
- $ fields [$ id ]->parseAnswerValues ($ input );
856
+ $ fieldValidities [$ id ] = $ fields [$ id ]->parseAnswerValues ($ input );
857
+ }
858
+ // any invalid field will invalidate the answers
859
+ $ valid = !in_array (false , $ fieldValidities , true );
860
+
861
+ // Mandatory field must be filled
862
+ // and fields must contain a value matching the constraints of the field (range for example)
863
+ if ($ valid ) {
864
+ foreach ($ fields as $ id => $ field ) {
865
+ if (!$ fields [$ id ]->isPrerequisites ()) {
866
+ continue ;
867
+ }
868
+ if (PluginFormcreatorFields::isVisible ($ field ->getQuestion (), $ fields ) && !$ fields [$ id ]->isValid ()) {
869
+ $ valid = false ;
870
+ break ;
871
+ }
872
+ }
873
+ }
874
+
875
+ if (!$ valid ) {
876
+ // Save answers in session to display it again with the same values
877
+ $ _SESSION ['formcreator ' ]['data ' ] = Toolbox::stripslashes_deep ($ input );
878
+ return false ;
854
879
}
880
+
855
881
return $ this ->saveAnswers ($ form , $ input , $ fields );
856
882
}
857
883
You can’t perform that action at this time.
0 commit comments