From 2fa9d10c575a5ac764d1c201d106f7bcbd47b774 Mon Sep 17 00:00:00 2001 From: Nick Liu Date: Wed, 6 Oct 2021 20:14:51 -0500 Subject: [PATCH] `e_form`: Handle attribute HTML entities properly for most form elements The result is a much more consistent form experience with less fear that some values put into an `e_form` method will break the web page. This commit covers the most common uses of `e_form` with HTML attribute quoting via `e_form::attributes()`. --- e107_handlers/form_handler.php | 768 +++++++++++++++++---------- e107_tests/tests/unit/e_formTest.php | 65 ++- 2 files changed, 527 insertions(+), 306 deletions(-) diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index 632a6ab8f..2d7c9491e 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -151,35 +151,46 @@ class e_form if(!empty($options['class'])) { - $class = "class='".$options['class']."'"; + $class = $options['class']; } else // default { - $class= "class='form-horizontal'"; + $class = "form-horizontal"; } if(isset($options['autocomplete'])) // leave as isset() { - $autoComplete = " autocomplete='".($options['autocomplete'] ? 'on' : 'off')."'"; + $autoComplete = $options['autocomplete'] ? 'on' : 'off'; } if($method === 'get' && strpos($target,'=')) { - list($url,$qry) = explode('?',$target); - $text = "\n
\n"; - - parse_str($qry,$m); - foreach($m as $k=>$v) + list($url, $qry) = explode('?', $target); + $text = "\nattributes([ + 'class' => $class, + 'action' => $url, + 'id' => $this->name2id($name), + 'method' => $method, + 'autocomplete' => $autoComplete, + ]) . ">\n"; + + parse_str($qry, $m); + foreach ($m as $k => $v) { - $text .= $this->hidden($k, $v); + $text .= $this->hidden($k, $v); } - - } - else + + } + else { - $target = str_replace('&', '&', $target); - $text = "\n\n"; + $text = "\nattributes([ + 'class' => $class, + 'action' => $target, + 'id' => $this->name2id($name), + 'method' => $method, + 'autocomplete' => $autoComplete, + ]) . ">\n"; } return $text; } @@ -630,37 +641,27 @@ class e_form */ public function carousel($name= 'e-carousel', $array=array(), $options = null) { - $interval = null; - $wrap = null; - $pause = null; $indicators = ''; $controls = ''; $act = varset($options['default'], 0); - - if(isset($options['wrap'])) - { - $wrap = 'data-wrap="'.$options['wrap'].'"'; - } - - if(isset($options['interval'])) - { - $interval = 'data-interval="'.$options['interval'].'"'; - } - - if(isset($options['pause'])) - { - $pause = 'data-pause="'.$options['pause'].'"'; - } $navigation = isset($options['navigation']) ? $options['navigation'] : true; $indicate = isset($options['indicators']) ? $options['indicators'] : true; - $start =' + $start = ' -