Skip to content
Advertisement

required attribute not working in form in codeigniter php

i have a shopping website in codeigniter, where have a product details page, in which user should select the color and size which is mandotory before adding to cart, so i did the following code:

<form action="">
  <input class="form-check-input" type="radio" name="size" id="rad" value="xssize" required>

  <select name="color" class="form-select" aria-label="Default select example" required>
    <option selected disabled>Select Item Color</option>
    <option value="RED">RED</option>
  </select>

  <a id="postGender" type="submit" href="<?php echo site_url('homecontroller/buy/'.$product->id); ?>" class="btn btn-to-cart"><span class="bag"></span><span>Add To cart</span><div class="clearfix"></div></a>

</form>

however, the required attriubute is not working, user is able to click the add to cart button, can anyone please tell me how to fix it, thanks n advance

Advertisement

Answer

Change your code to this.

<form action="<?php echo site_url('homecontroller/buy/'.$product->id); ?>">
  <input class="form-check-input" type="radio" name="size" id="rad" value="xssize" required>

  <select name="color" class="form-select" aria-label="Default select example" required>
    <option selected disabled>Select Item Color</option>
    <option value="RED">RED</option>
  </select>

  <button id="postGender" type="submit" class="btn btn-to-cart"><span class="bag"></span><span>Add To cart</span><div class="clearfix"></div></button>

</form>

Should work

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement