Let's say I want a form to direct to the current page, although I don't know what the page is named. How can I use php to print out the current page name into the action property?
php get current page name
You can get current page with $_SERVER['PHP_SELF'] function.
But in many cases I didn't use anything. Blank action will run script on current page.
Sonam
| Code: |
| $current = $_SERVER['PHP_SELF']; |
But in many cases I didn't use anything. Blank action will run script on current page.
Sonam
Try this:
| Code: |
| ...
<!-- this is HTML, not PHP (yet) --> <form method="post" action="http://<?php echo $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF']; ?>"> <!-- other form elements --> </form> ... |
dude try this
<?php
echo("<FORM ACTION = \"$_SERVER['PHP_SELF']\" method = \"POST\"");
?>
<?php
echo("<FORM ACTION = \"$_SERVER['PHP_SELF']\" method = \"POST\"");
?>
In fact, you could leave the action property blank. The browser will automatically submit the form to the current page.
