[resolved] page redirects to index.php and gives a 404 with submit button (5 posts)

  1. T.oby
    Posted 1 year ago #

    Hi, I was copying the w3c schools form validation example into a new page using the php-exec plugin. Unfortunately after clicking the submit button the page redirects to index.php and gives a 404 (Sorry, the page you are looking for is not found.). For any help on this I would be grateful.




  2. T.oby
    Posted 1 year ago #

    Sorry forgot to post the w3c schools link with the code: http://www.w3schools.com/Php/showphp.asp?filename=demo_form_validation_complete

  3. T.oby
    Posted 1 year ago #

    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:

      $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">
    echo $name

    Thanks for any help.

  4. T.oby
    Posted 1 year ago #

    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">

    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.

  5. T.oby
    Posted 1 year ago #

    Aaaah! :) - WordPress has reserved the word "name" which I used as variable name! Solved :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Exec-PHP
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.