开发者

php form validation not working

I have a form validation issue. Below is the logic that happens on submit (part of it at least.) In the for loop, we check an array of possible events that a site visitor can register for. If the user hasn't checked any events (these are checkboxes because a user can register for multiple events), we should enter the second if statement below, but for some reason we're not. I know that none of the post variables are set if nothing is checked and, by setting a session variable equal to the variable $ECEventCnt, I'm able to varify that if nothing is posted, that variable is equal to 0. However, we seem to never get into the second if statement. Any thoughts?

unset($_SESSION["ECEvents"]);
        $ECEventsArray = array();
        $ECEventCnt = 0;
        $_SESSION['debug'] = 'EC';
        for ($i=0; $i<count($Val_WhichEventTypes); $i++) {
            $key = $Val_WhichEventTypes[$i]["eventKey"];
            //echo 'key' . $key;
            if (isset($_POST["WhichEvent-" . $key]) && $_POST["WhichEvent-" . $key] == $key) {
                $_SESSION['debug'] .= ' we made it to the place.' . $_POST["WhichEvent-" . $key];
                 $ECEventsArray[$key] = $key ;
                 if (strlen($ECEventsArray[$key])) $ECEventCnt += 1;  // Only advance counter if EC Event is checked (key value is set)
            }
        }
        $_SESSION['ecventcount'] = $ECEventCnt;
        if ($ECEventCnt = 0) {
            set_step_INvalid(5);
            $_SESSION['debug'] .= ' we made it to the 2nd place.';
            $cnt += 1;
            $ValidationError .= ((strlen($ValidationError)==0) ? "" : ", ") . "<br />Please just select at least one Event Type/Time";
        }
        $_SESSION["ECEvents"] = $EC开发者_JAVA百科EventsArray;
        //valid_step52();

    }


if ($ECEventCnt = 0) {

should be

if ($ECEventCnt == 0) {

You are assigning to the variable $ECEventCnt, but what you mean to do is compare using it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜