WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. T.oby
    Member
    Posted 4 months 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.

    Thanks,

    Toby

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

  2. T.oby
    Member
    Posted 4 months 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
    Member
    Posted 4 months 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:

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

  4. T.oby
    Member
    Posted 4 months 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">
    </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.

  5. T.oby
    Member
    Posted 4 months ago #

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

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.