How to send information hidden through a form?

3

I want to send an information through a form, however I do not want it to appear in a field, that is, I want to send information via post, but it does not appear in input . How to do this?

    
asked by anonymous 27.02.2016 / 20:05

2 answers

7

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

<input type="hidden" name="input1" value="valor que você quer passar">
    
27.02.2016 / 20:08
1

Maybe it's not your case, but if you're doing this to implement the honeypot , where you put a hidden field to identify that your user is actually a bot spammer, input type="hidden" would not be the best form, since it is trivial for a bot to identify that field should not be filled in.

Other ways to do this are:

  • in 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.

    
27.02.2016 / 20:52