How to make an HTML field mandatory?

2

I need to validate the comments form, that is, only save if there is text insertion, the form is not mandatory in the form today. I've tried using the JQuery validation plugin , but I have not gotten any use how to use it. I want to leave the form mandatory following the example of the image below or with any type of mandatory text insertion.

<textarea cols='45' rows='7' name='comment' >

    
asked by anonymous 18.10.2016 / 13:31

2 answers

3

The form is an HTML form, which is being generated using PHP.

One solution I found for this field was to add the required attribute by adding required thus leaving the field with mandatory text input.

echo "<textarea cols='45' rows='7' name='comment' required>".$this->fields["comment"]."</textarea>";

Once this is done the browser will inform the user to fill in this field.

    
24.01.2017 / 15:28
0

You only add the required attribute that your input will be required.

<input type="text" placeholder="Buscar..." required>
    
26.01.2017 / 02:27