Thread Starter
T.oby
(@toby-1)
Thread Starter
T.oby
(@toby-1)
The issue seems to be the action in the submit button which was
<?php echo $_SERVER["PHP_SELF"];?>
and I changed it to
<?php echo esc_attr($_SERVER['REQUEST_URI']);?>
With this I can click on the button and the page is reloaded. However if any values in the text inputs are set I again get a 404 without redirecting to index.php but to the same url again.
My complete slimed down w3c example is:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$name = $_POST["name"];
}
?>
<form method="post" action="<?php echo esc_attr($_SERVER['REQUEST_URI']);?>">
Name: <input type="text" name="name" value="<?php echo $name;?>"><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
echo $name
?>
Thanks for any help.
Thread Starter
T.oby
(@toby-1)
I seems that the action attribute in WordPress is even not required because it redirects by default to the same page. Even the minimal example
<form method="post">
Name: <input type="text" name="name"><br>
<input type="submit" name="submit" value="Submit">
</form>
gives a 404 when the form has a value and the button is clicked. Is this the way to do a post in WordPress?
Any help is highly appreciated.
Thread Starter
T.oby
(@toby-1)
Aaaah! 🙂 – WordPress has reserved the word “name” which I used as variable name! Solved 🙂