Form Submission Hooks doesnt work when activated from forms?

Hey,

Ive made a form submission hook on an admin page of a plugin, in the hopes of being able to store some data in a database table.

Issue is that when the form activates the endpoint it stalls, and shows me a page that looks like the result of a wp_die() without any error message attached.

However if i curl the endpoint i have no issues, and my function from the main plugin file gets activated.

This is my Form:

<form action="<?php echo esc_url( admin_url( 'admin-post.php?action=wp_save_info' ) ); ?>" method="POST">
    <input type="hidden" name="action" value="save_info">
    <label for="name">Name:</label><br>
    <input type="text" name="name" value=""><br> 
    <label for="description">Description:</label><br>
    <textarea name="description"></textarea><br>
    <input type="submit" name="submit" value="Add Info">
    <?php wp_nonce_field( 'wp_save_info','wp_info_nonce' ); ?>
</form>

this is my Function:

function wp_save_info() {
     global $wpdb;
    $table_name = $wpdb->prefix . 'info';

    $name = sanitize_text_field( $_POST['name'] );
    $description = sanitize_text_field( $_POST['description'] );

    $wpdb->insert( 
        $table_name, 
        array( 
            'name' => $name, 
            'description' => $description
        ) 
    );

    wp_redirect( admin_url( 'admin.php?page=wp_info_create' ) );
    exit;
}   
add_action( 'admin_post_wp_save_info', 'wp_save_info' );

Any good ideas of what I might be missing of configurations since i cant get the form submission to work, but the endpoint does work?

Thank you guys in advance.

  • This topic was modified 9 hours, 18 minutes ago by kafal.
  • This topic was modified 9 hours, 18 minutes ago by kafal.
  • This topic was modified 9 hours, 17 minutes ago by kafal. Reason: some typos when trying to simplify my question

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer