Required does not work

Asked

Viewed 3,582 times

0

I would like the fields not to be sent in empty, so I tried using the required.. but it is not working. What is the reason why?

<form action="https:/----Site---" method="POST">
  <input type=hidden name="oid" value="00Dj0000001qrSu">
  <input type=hidden name="retURL" value="http://-----/?msg=ok">
  <input type=hidden name="lead_source" value="Formulário Site">
  <table>
    <tr>
      <td>
        <input type="text" name="first_name" placeholder="Nome:" maxlength="250" required="required" />
      </td>
      <td>
        <input type="text" name="email" placeholder="E-mail:" maxlength="250" required="required" />
      </td>
    </tr>
    <tr>
      <td>
        <input type="text" name="company" placeholder="Empresa:" maxlength="250" required="required" />
      </td>
      <td>
        <input type="text" name="phone" placeholder="Telefone:" maxlength="250" required="required" />
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <textarea name="description" placeholder="Mensagem/Comentários:" rows="4" required="required"></textarea>
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <input type="submit" name="enviar" value="Enviar" />
      </td>
    </tr>
  </table>
</form>

  • 1

    try to put required="required"

  • This code is inside a form ? How is the request being sent ? Could you publish the whole form ?

  • I did the editing to make it clearer.

  • Thiago, it didn’t work.

  • What doesn’t work? Can it send the form even with a blank value? Is that it? Or it doesn’t send anything from the form?

  • I tested your code and it apparently worked, what is the result ? It at least points out that the field is not filled in ?

  • Can even send the form when it is empty

  • Mayllon he does not point out that the field is blank, simply sends the message normally.

  • 1

    If you want to let your code dry, instead of repeating required="required" in all form fields, if you use jQuery on your page, just put a line of script so that all fields have required: $("form *").attr("required","required");.

  • @Dvdsamm the problem has already been solved in response, the AP browser was not supported yet.

Show 5 more comments

2 answers

1


I performed the test and it’s working for me. "required" was a feature added to HTML5 your browser needs to have support for it. Run a test on Chrome for example.

You can use the website: http://html5test.com/ to find out if your browser is suitable.

<form action="https:/----Site---" method="POST">
    <input type=hidden name="oid" value="00Dj0000001qrSu">
    <input type=hidden name="retURL" value="http://-----/?msg=ok">
    <input type=hidden name="lead_source" value="Formulário Site">
    <table>
        <tr>
            <td>
                <input type="text" name="first_name" placeholder="Nome:" maxlength="250" required="required" />
            </td>
            <td>
                <input type="text" name="email" placeholder="E-mail:" maxlength="250" required="required"/>
            </td>
        </tr>
        <tr>
            <td>
                <input type="text" name="company" placeholder="Empresa:" maxlength="250" required="required" />
            </td>
            <td>
                <input type="text" name="phone" placeholder="Telefone:" maxlength="250" required="required" />
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <textarea name="description" placeholder="Mensagem/Comentários:" rows="4" required="required"></textarea>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" name="enviar" value="Enviar" />
            </td>
        </tr>
    </table>
</form>

  • Cool, really the code was right, However in my browser I can send blank. And my partner here in front not.. how strange

0

The REQUIRED attribute was inserted with HTML5 and only works in some versions of the browsers.

Possibly you are testing in a browser that is not supported, follow the list of browsers that accept and validate the REQUIRED attribute

http://www.w3schools.com/tags/att_input_required.asp

  • I’m using the latest version of Google Chrome.

  • This code there that you put in the STACK is working without problems, has more code that you did not put?

  • Really now it’s worked out. It’s already been solved.

Browser other questions tagged

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