WordPress.org

Support

Support » Plugins and Hacks » Exec-PHP » [Resolved] page redirects to index.php and gives a 404 with submit button

[Resolved] page redirects to index.php and gives a 404 with submit button

  • 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.

    Thanks,

    Toby

    https://wordpress.org/plugins/exec-php/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Sorry forgot to post the w3c schools link with the code: http://www.w3schools.com/Php/showphp.asp?filename=demo_form_validation_complete

    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.

    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.

    Aaaah! 🙂 – WordPress has reserved the word “name” which I used as variable name! Solved 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] page redirects to index.php and gives a 404 with submit button’ is closed to new replies.
Skip to toolbar