Code Duplication    Length = 8-8 lines in 2 locations

htdocs/class/xoopsform/formcheckbox.php 1 location

@@ 197-204 (lines=8) @@
194
        if (!empty($this->customValidationCode)) {
195
            return implode(NWLINE, $this->customValidationCode);
196
            // generate validation code if required
197
        } elseif ($this->isRequired()) {
198
            $eltname    = $this->getName();
199
            $eltcaption = $this->getCaption();
200
            $eltmsg     = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption);
201
            $eltmsg     = str_replace('"', '\"', stripslashes($eltmsg));
202
203
            return NWLINE . "var hasChecked = false; var checkBox = myform.elements['{$eltname}']; if (checkBox.length) {for (var i = 0; i < checkBox.length; i++) {if (checkBox[i].checked == true) {hasChecked = true; break;}}} else {if (checkBox.checked == true) {hasChecked = true;}}if (!hasChecked) {window.alert(\"{$eltmsg}\");if (checkBox.length) {checkBox[0].focus();} else {checkBox.focus();}return false;}";
204
        }
205
206
        return '';
207
    }

htdocs/class/xoopsform/formselect.php 1 location

@@ 216-223 (lines=8) @@
213
        if (!empty($this->customValidationCode)) {
214
            return implode("\n", $this->customValidationCode);
215
            // generate validation code if required
216
        } elseif ($this->isRequired()) {
217
            $eltname    = $this->getName();
218
            $eltcaption = $this->getCaption();
219
            $eltmsg     = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption);
220
            $eltmsg     = str_replace('"', '\"', stripslashes($eltmsg));
221
222
            return "\nvar hasSelected = false; var selectBox = myform.{$eltname};" . "for (i = 0; i < selectBox.options.length; i++) { if (selectBox.options[i].selected == true && selectBox.options[i].value != '') { hasSelected = true; break; } }" . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }";
223
        }
224
225
        return '';
226
    }