5

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.

1
  • is it redirecting to test.php? How do you know it is not working? also you should use a consistent form of the php tag. The long version is often preferred because it avoids confusion/problems with ASP. Commented Apr 26, 2010 at 8:16

4 Answers 4

8

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.

Sign up to request clarification or add additional context in comments.

Comments

4

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>

Comments

2

Try this

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

2 Comments

Or <form name="upload" action"<?=$url;?>" method="post">, without the single quotes wrapping the php snippet.
If it's not working, try looking at the source output and paste that line
0

Remove your single quotes:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.