0

I want to include

action="<?php echo $_SERVER['PHP_SELF']; ?>"

in $render_form variable. But the following code does not work:

<?php $render_form = '<form method="post" action="<?php echo 
  $_SERVER['PHP_SELF']; ?>">
  <input type="text" name="name">
  <br>
  <input type="submit" name="submit" value="Submit Form">
  <br> 
  </form>'; 
?>

The following code (without php tag) works:

<?php $render_form = '<form method="post" action="">
  <input type="text" name="name">
  <br>
  <input type="submit" name="submit" value="Submit Form">
  <br>
  </form>'; 
?>

1 Answer 1

1

If I understood you, this should fit your issue

<?php $render_form = '<form method="post" action="'. $_SERVER['PHP_SELF'] .'">
  <input type="text" name="name">
  <br>
  <input type="submit" name="submit" value="Submit Form">
  <br> 
  </form>'; 
?>
Sign up to request clarification or add additional context in comments.

2 Comments

Hi BanNsS1, thanks for the reply- your code works. Would it be possible to provide explanation for this syntax: '. $_SERVER['PHP_SELF'] .' ?
Yeah, it's the way to concatenate strings in PHP: $string = "My name is ". $name .", nice to meet you ". $stranger_name; php.net/manual/en/language.operators.string.php

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.