forms - php $_SERVER POST methods the new and more efficient style? -
i wrote relatively simple usable php query logging software couple of years , setup "plain vanilla" form, post method has separate page processes form below
1) input form displays submit button calls process-form.php 2) process-form.php processes form (e.g. enters data onto database) 3) process-form.php displays message if fine or not.
now, when go through php tutorials, teaching having form submit upon using $_server
<?php //use $_server function decipher if post method has been triggered if ($_server["request_method"] == "post") { $name = $_post["name"]; $email = $_post["email"]; $message = $_post["message"]; //todo: send email, etc. } ?> i can see benefits of of method code remains compact have go 1 page instead of going other pages if need fix something. prevalent method now? asking trying learn. thank you!
you can use isset() or sizeof() or empty()
if (isset($_post)) { $name = $_post["name"]; $email = $_post["email"]; $message = $_post["message"]; //todo: send email, etc. } or
if (sizeof($_post) > 0) { $name = $_post["name"]; $email = $_post["email"]; $message = $_post["message"]; //todo: send email, etc. } or
if (!empty($_post)) { $name = $_post["name"]; $email = $_post["email"]; $message = $_post["message"]; //todo: send email, etc. }
Comments
Post a Comment