• Resolved CeilingTiles

    (@ceilingtiles)


    I am new to plugin development.

    I have created a page (accessed via shortcode) with a form for the user to fill out. The problem is, when they press the Submit button, it’s taking them to a page that doesn’t exist—and I want them coming back to this page.

    Here’s what I’ve got—

    <?php
    
    // disable direct file access
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    }
    
    // define variables and set to empty values
    $nickname = "";
    
    ?>
    
    <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 
    Nickname <input type="text" name="nickname"><br>
    <input type="submit">
    </form>
    
    <?php
    echo $nickname;

    Any help would be greatly appreciated. Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    An empty action value will submit to the same page: action="". “PHP_SELF” gives you the PHP filename, not the WP permalink that you need. And you are blocking direct access to that PHP file anyway (which is fine to do, assuming this is part of your WP site).

    Thread Starter CeilingTiles

    (@ceilingtiles)

    That worked.

    THANK YOU SO MUCH!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘How to submit a form’ is closed to new replies.