Php empty field required

I have a contact form that has a hidden field (profession). I am trying to check the script to make sure that this hidden field is empty, and if so, send me the result of the form. If this field is NOT empty, the form will not be sent to me.

Initially, my code was:

if(isset($_POST['profession']) && $_POST['profession'] == ''){ 

But I believe that this is really wrong and makes the profession field empty? Therefore, I believe that the code should be simple:

  if(!isset($_POST['profession'])){ 

I got it right. What would be the best way to code this?

+6
source share
1 answer

It's nice to see that you are using the honeypot method to prevent spam. The best you can do is simply:

 if (empty($_POST['profession'])){ // Send form result. } 

The empty() function evaluates to true when it is an empty string ( '' ) or when a variable or array element does not exist at all. For more information on comparison, see here: http://php.net/manual/en/types.comparisons.php

+4
source

All Articles