简体   繁体   中英

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

I want to pass php variable value as a action to html form. I am trying as follows, but it is not working.

<?php
    $url='test.php';
?>

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

All this code are in one php file.

Have you tried <?php echo $url ?> If it works, then short_open_tag in the php.ini is turned off. That means you will need to either turn it on or use the long open tag <?php throughout your code.

Sounds like you need to enable short_open_tag if your example doesn't work.

<?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>

Alternately, write it like this:

<?php
    $url='test.php';
?>

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

试试这个

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

删除你的单引号:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM