Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aaadkins's avatar

Checkbox input field returning a string?

Hi, in my register form I have a checkbox input to accept my terms which the controller should show only as 'on' if its selected. However, its accepting string values for some strange reason. Can anyone offer any insight into this and tell me what could be wrong? The code to the checkbox is below. Thanks

 <div class="mb-5">
          <div class="custom-control custom-checkbox d-flex align-items-center text-muted">
           <input type="checkbox" class="custom-control-input" id="termsCheckbox" name="termsCheckbox" data-msg="Please accept our Terms and Conditions.">
                  <label class="custom-control-label" for="termsCheckbox">
                    <small>
                      I agree to the
                      <a class="link-underline" href="../pages/terms.html">Terms and Conditions</a>
                    </small>
                  </label>
                </div>
                <div class="checkboxerror">
                </div>
              </div>
0 likes
5 replies
Snapey's avatar

give the input element a value of "on" ?

aaadkins's avatar

@Snapey Thanks, yes I can give that a try but how would that input field even be able to take a string value if its just a checkbox?

1 like
Snapey's avatar

@aaadkins I have no idea by what you mean "take a string value"

You are seeing a string in the controller?

Do you have javascript interacting with this element? I notice the data attribute.

aaadkins's avatar

@Snapey Yes I am seeing it in the controller. I am using jquery validate on this field and have it set to required.

  $( "#registerForm" ).validate({
          rules: {
            password: "required",
            termsCheckbox: {
                required: true,
            },
            confirmPassword: {
              equalTo: "#signinSrPassword"
            }
          },
          messages: {
            termsCheckbox : "Please agree"
          },
            errorPlacement: function(error, element) {

              if (element.is(":checkbox"))

                    //error.appendTo(element.child());
                error.insertAfter($(".checkboxerror"));
                else
                    error.appendTo(element.parent());
            },
        });
Snapey's avatar

@aaadkins what do you see in the controller? Any chance you have cut and paste the field within the form and forgot to change the name?

Please or to participate in this conversation.