Required field in cart not working

Highlighted
New Member
1 0 1

I have been struggling with this code for weeks now, and no solution on the Community boards so far has helped. The nice people in the Shopify chat were not able to help me as they said they, like me, are not really coders.

 

My site is for a school and in the cart I need my custom field "Teacher" to be required. I used the UI Elements Generator https://ui-elements-generator.myshopify.com/pages/cart-attribute to build my code and I added it to cart.liquid. As you can see I selected "required":

 

<p class="cart-attribute__field">
<label for="teacher">Teacher</label>
<input required class="required" id="teacher" type="text" name="attributes[Teacher]" value="{{ cart.attributes["Teacher"] }}">
</p>

 

It shows up and works, but it is not required and folks are able to bypass it. 

 

Some fixes I found that do not work:

 

  • Adding "required" to the end of the input tag like this -->  <input required class="required" id="teacher" type="text" name="attributes[Teacher]" value="{{ cart.attributes["Teacher"] }}" required> OR <input required class="required" id="teacher" type="text" name="attributes[Teacher]" value="{{ cart.attributes["Teacher"] }}" required />
  • editing it to say required="required"

Any ideas?? I really need a more experienced coder!

1 Like