html - How do I make a PHP form that submits to self? -


how make self-posting/self-submitting form, i.e. form submits results itself, instead of submitting form?

the proper way use $_server["php_self"] (in conjunction htmlspecialchars avoid possible exploits). can skip action= part empty, not w3c valid, works in (all?) browsers - default submit self if it's empty.

here example form takes name , email, , displays values have entered upon submit:

<?php if (!empty($_post)): ?>     welcome, <?php echo htmlspecialchars($_post["name"]); ?>!<br>     email <?php echo htmlspecialchars($_post["email"]); ?>.<br> <?php else: ?>     <form action=<?php echo htmlspecialchars($_server["php_self"]); ?> method="post">         name: <input type="text" name="name"><br>         email: <input type="text" name="email"><br>         <input type="submit">     </form> <?php endif; ?> 

Comments