@@ -255,6 +255,20 @@ private function checkBeforeSave($input) {
255255 return [];
256256 }
257257
258+ // Values are required for GLPI dropdowns, dropdowns, multiple dropdowns, checkboxes, radios
259+ $ itemtypes = ['select ' , 'multiselect ' , 'checkboxes ' , 'radios ' ];
260+ if (in_array ($ input ['fieldtype ' ], $ itemtypes )) {
261+ if (isset ($ input ['values ' ])) {
262+ if (empty ($ input ['values ' ])) {
263+ Session::addMessageAfterRedirect (
264+ __ ('The field value is required: ' , 'formcreator ' ) . ' ' . $ input ['name ' ],
265+ false ,
266+ ERROR );
267+ return [];
268+ }
269+ }
270+ }
271+
258272 if (!isset ($ input ['fieldtype ' ])) {
259273 $ input ['fieldtype ' ] = $ this ->fields ['fieldtype ' ];
260274 }
@@ -266,7 +280,8 @@ private function checkBeforeSave($input) {
266280 if (isset ($ input ['regex ' ]) && !empty ($ input ['regex ' ])) {
267281 // Avoid php notice when validating the regular expression
268282 set_error_handler (function ($ errno , $ errstr , $ errfile , $ errline , $ errcontext ) {});
269- $ isValid = !(preg_match ($ input ['regex ' ], null ) === false );
283+ $ regex = Toolbox::stripslashes_deep ($ input ['regex ' ]);
284+ $ isValid = !(preg_match ($ regex , null ) === false );
270285 restore_error_handler ();
271286
272287 if (!$ isValid ) {
@@ -298,7 +313,9 @@ public function prepareInputForAdd($input) {
298313 foreach ($ input as $ key => $ value ) {
299314 if ($ input ['fieldtype ' ] != 'dropdown '
300315 || $ input ['fieldtype ' ] != 'dropdown ' && $ key != 'values ' ) {
301- $ input [$ key ] = plugin_formcreator_encode ($ value );
316+ if ($ key != 'regex ' ) {
317+ $ input [$ key ] = plugin_formcreator_encode ($ value );
318+ }
302319 }
303320 }
304321
@@ -361,7 +378,9 @@ public function prepareInputForUpdate($input) {
361378 && !($ input ['fieldtype ' ] == 'checkboxes ' && ($ key == 'values ' || $ key == 'default_values ' ))
362379 && !($ input ['fieldtype ' ] == 'radios ' && ($ key == 'values ' || $ key == 'default_values ' ))
363380 && !($ input ['fieldtype ' ] == 'multiselect ' && ($ key == 'values ' || $ key == 'default_values ' ))) {
364- $ input [$ key ] = plugin_formcreator_encode ($ value );
381+ if ($ key != 'regex ' ) {
382+ $ input [$ key ] = plugin_formcreator_encode ($ value );
383+ }
365384 } else {
366385 $ input [$ key ] = str_replace ('\r\n ' , "\r\n" , $ input [$ key ]);
367386 }
0 commit comments