1

I am using a self hosted email marketing service.

I have built the form.... embedded it..

But when someone does not add a value for their birthday.. it defaults to Dec 31, 1969 using a date input.

I want that to be a value of nothing if they did not add their bday as ( mm/dd/yyyy)

The reason why, if i leave it as is.. everyone who doesn't complete the birthday date filed will be getting auto emails saying Happy birthday on Dec 31, 1969.

How can a check to see if its blank in php and then give it a value that wont send out auto emails? Is this even possible?

Dharman
  • 30,962
  • 25
  • 85
  • 135
MuhuPower
  • 404
  • 3
  • 25

2 Answers2

2
if (empty($_POST['birthday'])) 
{
  $empty_bday_flag = true;
}
else
{
  $empty_bday_flag = false;
}

The empty function tests if a value is set and not empty, if nothing is set then the user didn't fill it in, so we can set the $empty_bday_flag to true, otherwise we set it to false.

EDIT 1: As gustavo.lei pointed out one has to use empty here rather than isset.
EDIT 2: As Dharman pointed out one can simplify this to $empty_bday_flag = empty($_POST['birthday']);.

Tox
  • 373
  • 4
  • 13
  • 1
    You could just use null-coalesce operator or even better just assign the value of isset to $bday_flag – Dharman Sep 16 '19 at 17:58
  • yes, you can most definitely do that, but it's harder to understand for people who don't know it. – Tox Sep 16 '19 at 20:40
2

I believe in this case, you should use a empty instead isset, because your form will always be sent with the "birthday" field, your user filling data or not. So, doing isset, will only verify if the birthday field is set and if the value is empty, the code will return isset as true.

I'd do something like this:

$bdayFilled = true;
if(empty($_POST['birthday']))
    $bdayFilled = false;

or a one line code

 $bdayFilled = !empty($_POST['birthday'];

In the code above, if the value of birthday is empty, $bdayFilled will be set as false else will be true.

For better understanding, I suggest you read:

gustavo.lei
  • 141
  • 1
  • 7