ShaneW ShaneW - 1 month ago 8
PHP Question

php <?php stored in a variable to build a form not

Really simple question, yet I can't seem to find an answer.

I'm building a form into a variable $form to display depending on certain criteria.

$form .= '<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> "method="post">';


However, this particular line is making "method="post"> in my form. I've tried escaping all "" and still cant fix it. What am I missing?

Answer

Change it to this:

$form .= '<form action="' . htmlspecialchars($_SERVER["PHP_SELF"]) . ' "method="post">';

When you're inside a php block you shouldn't try and use <?php ?> also as you're just creating a string you don't need to echo out another string inside it.

Hope this helps!