How to send hidden information through a form?

Asked

Viewed 50 times

3

I want to send information through a form, however I do not want it to appear in a field, I mean, I want to send information via post, but without it appearing in a input. How to do this?

2 answers

7


In input, set the attribute hidden and place the value within value, thus:

<input type="hidden" name="input1" value="valor que você quer passar">

1

This may not be your case, but if you are doing this to implement the technique of honeypot, where you place an Hidden field to identify that your user is actually a spammer bot, a input type="hidden" would not be the best way, since it is trivial for a bot to identify that this field should not be filled in.

Other ways to do this are:

  • javascript:

    document.querySelector('input[name="NAME"]')[0].style.visibility = 'hidden';
    

    or

    document.querySelector('input[name="NAME"]')[0].style.display = 'none';
    
  • in jQuery:

    $('input[name="NAME"]').hide();
    
  • in CSS:

    input[name="NAME"] {
        display: none;
    }
    

Yes, a bot that has a Javascript and CSS parser will also be able to identify that the input should not be filled in, but the above method already prevents simple bots from spamming your site.

Browser other questions tagged

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