0
 <?php 
 $a=3;
 $dir= '/php/';
?>
 <?php if($a ==3){ ?>
<form action="/php/form.php" method="post">
 <p>Name: <input type="text" name="name" /></p>
 <p>Age: <input type="text" name="age" /></p>
 <p><input type="submit" /></p>
</form>
<?php } ?>

I want to pass $dir in form action ,like action=$dir.form.php. It's possible?

0

3 Answers 3

4

Yes it is possible you need to simply pass $dir to action Try

<form action="<?php echo $dir;?>form.php" method="post">
Sign up to request clarification or add additional context in comments.

3 Comments

glad to know it's helpful for you you can accept/upvote helpful answers
@RakeshSharma There's a time limit until the OP can accept. + if you ask me, +50 for this simple answer is rewarding enough :).
@DaveChen i know :) i am suggesting only
1

You can embed php tags anywhere in your html code. Rewrite your snippet like this:

<?php 
   $a=3;
   $dir= '/php/';
 ?>
 <?php if($a ==3){ ?>
<form action="<?php echo $dir."form.php" ?>" method="post">
<p>Name: <input type="text" name="name" /></p>
<p>Age: <input type="text" name="age" /></p>
<p><input type="submit" /></p>

Comments

1

Yes it is possible

 <?php 
 $a=3;
 $dir= '/php/';

 if($a ==3){ ?>
   <form action="<?php echo $dir.'form.php'; ?>" method="post">
   <p>Name: <input type="text" name="name" /></p>
   <p>Age: <input type="text" name="age" /></p>
   <p><input type="submit" /></p>
</form>
<?php } ?>

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.