php - make a if statement run only when submit button is clicked -


here have form , php code run when submit button clicked.but "if" block run page reloads.as if $_post array not empty.i can try single element,like !empty($_post['name']).but want test on universal $_post array.how can it?

<?php  require_once 'input.php';   if(input::exists()){   print_r($_post);   $arr=array('ball');   echo $arr[0]; } ?>  <form action='' method='post'>    name:<input type='text' name='name' ></br>    <input type='submit' value='submit'> </form> 

input.php file:

  class input{      public static function exists($type='post'){          switch($type){             case 'post':                return (!empty($_post))?true:false;                break;             default:                return (!empty($_get))?true:false;                brek;           }      }   } 

why need input class? this:

if ($_post['name']) {     print_r($_post);     $arr=array('ball');     echo $arr[0]; } 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -