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

时间:2022-10-16 10:58:23

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文件中。

4 个解决方案

#1


6  

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.

你有试过< ?php echo $url ?>如果有效,则在php中使用short_open_tag。ini被关闭。这意味着您需要打开它或者使用long open标记

#2


2  

Sounds like you need to enable short_open_tag if 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>

#3


1  

Try this

试试这个

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

#4


0  

Remove your single quotes:

把你的单引号:

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

#1


6  

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.

你有试过< ?php echo $url ?>如果有效,则在php中使用short_open_tag。ini被关闭。这意味着您需要打开它或者使用long open标记

#2


2  

Sounds like you need to enable short_open_tag if 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>

#3


1  

Try this

试试这个

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

#4


0  

Remove your single quotes:

把你的单引号:

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