0

This is my code:

        <div class="two-columns">
            <div class="col-half">
                <label for="city">Città</label>
                <input type="text" name="city" class="required">
            </div>
            <div class="col-half">
                <label for="province">Provincia</label><br>
                <select name="province" class="required">
                    <option value="">Seleziona la provincia</option>
                </select>
            </div>
        </div>

As you can see I put the "class required" in the dropdown because the user must choose a value. All works fine but I cannot see the alert message if I miss to select an item from the dropdown; the form is not sent, correct, but the alert is not shown. Any hints?

Ras
  • 628
  • 1
  • 11
  • 29
  • what is that class="required"? isn't it required attribute?? – Vignesh May 06 '15 at 14:35
  • kindly post your controller where you set_rules for validation in codeigniter. and class = requried doesn't mean anything actually its required paramter in frontend to make a field required. so just post your controller where you pass these values. – imran qasim May 06 '15 at 14:35

2 Answers2

1

You should be able to just have it as

<select name="province" required>
    <option value="">Seleziona la provincia</option>
</select>

Here's a link to a helpful stackoverflow post about it:

Can I apply the required attribute to <select> fields in HTML5?

Community
  • 1
  • 1
Jeremy Jackson
  • 2,247
  • 15
  • 24
1

If you add like this class='required' it will not do any kind of validation.

  • The class attribute is mostly used to point to a class in a style sheet. However, it can also be used by a JavaScript (via the HTML DOM) to make changes to HTML elements with a specified class.

If you want to do validation you can do it in different ways.

  • By Using HTML5 required attribute

    For Ex : <select name="" required>

  • Server side form validation in codeigniter. Dont forgot to include validation libraray $this->load->library('form_validation');

    For Ex : $this->form_validation->set_rules("province","province","required")

  • Finally you can use jquery or javascript validation

    Hope it will help. Thanks

Krishna38
  • 707
  • 1
  • 16
  • 43