php - Sometimes $_POST return empty results after form submission -


i have html form , use isset check if post variables set, process them (send them via email or google spreadsheet). sometimes receive empty result(s), if variable(s) is/are null or empty, not empty space. why happening? missing something?

 <?php if(isset($_post["name"]) && isset($_post["tel"])){       $name  = $_post["name"];       $phone  = $_post["phone"];       $message="name: $name \nphone : $phone \n";        require 'phpmailer/phpmailerautoload.php';        $mail = new phpmailer;       $mail->setfrom('from@mail.com', 'from name');       $mail->addaddress('to@gmail.com', 'to name');       $mail->subject  = 'message subject';       $mail->body     = $message; ?>   <form enctype="multipart/form-data" action="#" method="post">                           <input id="name" type="text" name="name" title="enter name" placeholder="name" required >            <input id="phone" type="phone" name="phone" pattern="0(6|5)([-. ]?[0-9]{2}){4}" title="enter phone" placeholder="phone" required >      <button type="submit" id="submit" name="submit">send</button>                        </form> 

p.s. fields may have rtl arabic entries sometimes. i'm using client-side javascript validation check if fields valid , not empty. understand client-side validation can flooded since it's client-side , since browsers different each other, however, can't figure out how empty entries still returning true if(isset($_post[])! normal behaviour of isset($_post[]) when input fields empty? checking if !empty($_post[]) correct , relevant in case? .

isset() checks variable set , not null.

http://php.net/manual/en/function.isset.php

if it's set , empty, isset() returns true.

you need use empty() check empty value.

http://php.net/manual/en/function.empty.php

you can strict check against value if know check against:

if (isset($_post['name']) && $_post['name'] !== '') 

Comments