php 如何将php变量值传递给html表单的action属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2711902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:26:31  来源:igfitidea点击:

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

phphtml

提问by MAS1

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

我想将 php 变量值作为一个动作传递给 html 表单。我正在尝试如下,但它不起作用。

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

所有这些代码都在一个 php 文件中。

回答by webbiedave

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 <?phpthroughout your code.

有没有试过<?php echo $url ?>如果可以,说明php.ini中的short_open_tag是关闭的。这意味着您需要<?php在整个代码中打开它或使用长开放标签。

回答by rmarscher

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

如果您的示例不起作用,听起来您需要启用short_open_tag

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

回答by nc3b

Try this

尝试这个

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

回答by Jakob Kruse

Remove your single quotes:

删除您的单引号:

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