How to make an HTML field mandatory?

Asked

Viewed 29,131 times

3

I need to validate the comments form, IE, only save if there is text insertion, today in the form is not required to insert text. I’ve tried using the Jquery validation plugin, but I couldn’t get excited about how to use it. I want to leave the required form by following the example of the image below or with any type of insertion required text.

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

*Formulário comentários*

  • 1

    Colleague, use the required tag, don’t need to invent too much. Search for HTML5.

  • Already solved here buddy.

  • Voce could show you the change you made

3 answers

6

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

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

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

Done this the browser will inform user to fill this field.

Campo de texto com balão indicativo de preenchimento obrigatório

3

Only you add the attribute required that your input will be mandatory.

<input type="text" placeholder="Buscar..." required>

-1

As previous colleagues mentioned, use the required tag in the inputs and for security inplemente an if for validation as for example:

if(isset($_POST['emailAdmLogin']) && !empty($_POST['emailAdmLogin']) && isset($_POST['senhaAdmLogin'])&& empty($_POST['senhaAdmLogin'])){

    $emailAdmLogin = addslashes($_POST['emailAdmLogin']);
    $senhaAdmLogin = addslashes($_POST['senhaAdmLogin']);
    $this->validaAcesso($emailAdmLogin,$senhaAdmLogin);       
}else{
    header('app/Public/Admin');
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.