How to pass php variable value to action attribute of html form

I want to pass the value of a php variable as an action to an html form. I am trying to do the following, but it does not work.

<?php $url='test.php'; ?> <html> <body> <form name="upload" action="<?=$url?>" method="post" > <input type="submit" value="submit"> </form> </body> </html> 

All this code is in a single php file.

+4
source share
4 answers

Have you tried <?php echo $url ?> If it works, then short_open_tag is disabled in php.ini. This means that you need to either enable it or use the long open <?php tag throughout your code.

+6
source

It looks like you need to enable short_open_tag if your example is not working.

 <?php ini_set('short_open_tag', 'on'); $url='test.php'; ?> <html> <body> <form name="upload" action="<?=$url?>" method="post" > <input type="submit" value="submit"> </form> </body> </html> 

Alternatively, write it as follows:

 <?php $url='test.php'; ?> <html> <body> <form name="upload" action="<?php echo $url ?>" method="post" > <input type="submit" value="submit"> </form> </body> </html> 
+2
source

try it

 <form name="upload" action="<? echo $url ?>" method="post" > 
+1
source

Remove single quotes:

 <form name="upload" action="<?=$url?>" method="post"> 
0
source

Source: https://habr.com/ru/post/1307996/


All Articles