r/PHPhelp • u/DownFromHere • Mar 29 '26
Basic Beginner Question for Form Issue
I am working on PHP form handling with a local Wordpress site running on WPEngine using the CSS & Javascript ToolBox. My script is in the header. I can't get the form input to pass to PHP successfully no matter what I try.
I have tried POST, GET, and REQUEST. I have tried writing the php file manually in the HTML code and writing it with <?php echo $_SERVER\['SCRIPT_NAME'\];?> and both $_SERVER['SCRIPT_FILENAME'] and $_SERVER['PHP_SELF']. I have tried removing the ".php" tag on the end of the file name. None of them have worked.
My only output is "not registered". Since I have tried to so many methods, I think the input is not successfully passing to PHP. It's also changing my page layout that I've already written with CSS. I have an onclick() function written in Javascript for the submission button as well.
HTML code:
<section><form id="form1" action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
<ol id="form2">
<li>
<label for="choice1">Choice 1 </label>
<input id="opt1" class="choices" name="opt1" required="" type="text"/>
<ul id="infoOpt1" class="optionInfo">
<li>Info about Choice 1</li>
</ul>
</li>
<li>
<label for="choice2">Choice 2 </label>
<input id="opt2" class="choices" name="opt2" required="" type="text" />
<ul id="infoOpt2" class="optionInfo">
<li>Info about Choice 2</li>
</ul>
</li>
</ol><Input type="submit" value="submit" onclick="changeColor()"> </form></section>
PHP Code:
<? php
ECHO 'Hello World!<br>';
$opt1 = isset($_POST['opt1']) ? $_POST['opt1'] : 'not registered';
echo htmlspecialchars($opt1);
?>