Code Duplication    Length = 19-19 lines in 2 locations

class/Form/Elements/SmartFormCheckElement.php 1 location

@@ 45-63 (lines=19) @@
42
        $js .= 'var hasSelections = false;';
43
        //sometimes, there is an implicit '[]', sometimes not
44
        $eltname = $this->getName();
45
        if (false === strpos($eltname, '[')) {
46
            $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) {
47
                if (myform['{$eltname}[]'][i].checked) {
48
                    hasSelections = true;
49
                }
50
51
            }
52
            if (hasSelections === false) {
53
                window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n";
54
        } else {
55
            $js .= "for (var i = 0; i < myform['" . $eltname . "'].length; i++) {
56
                if (myform['{$eltname}'][i].checked) {
57
                    hasSelections = true;
58
                }
59
60
            }
61
            if (hasSelections === false) {
62
                window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n";
63
        }
64
65
        return $js;
66
    }

class/Form/SmartObjectForm.php 1 location

@@ 824-842 (lines=19) @@
821
                      || 'smartformcheckelement' === strtolower(get_class($elt))) {
822
                $js .= 'var hasSelections = false;';
823
                //sometimes, there is an implicit '[]', sometimes not
824
                if (false === strpos($eltname, '[')) {
825
                    $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) {
826
                        if (myform['{$eltname}[]'][i].checked) {
827
                            hasSelections = true;
828
                        }
829
830
                    }
831
                    if (hasSelections === false) {
832
                        window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n";
833
                } else {
834
                    $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) {
835
                        if (myform['{$eltname}'][i].checked) {
836
                            hasSelections = true;
837
                        }
838
839
                    }
840
                    if (hasSelections === false) {
841
                        window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n";
842
                }
843
            } else {
844
                $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n";
845
            }