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?

2
  • what is that class="required"? isn't it required attribute?? Commented May 6, 2015 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. Commented May 6, 2015 at 14:35

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.