Checking if fields empty

I want to check is the fields of some form are empty…as such I use this code(for mail for example):

if(trim(mail)=='')
{ //it is empty}

The question is if checking if a field is empty sanitation filter plays a role…(santizing the string more specifically).

Or the above code will suffice and nothing else is needed.

This is what I do:

 $mail= isset($mail]) ? trim($mail) : '';

Then check to see if it’s empty or not with a if statement, for someone could intentionally or not just put spaces in the input field.
I’m assuming you meant to put a $ in front of mail. :wink:

if ( empty($var) ){
//code if empty
}

or if its a post and you are not sure that the variable exsists use isset(), e.g. $_POST/$_GET

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.