After form submission want to show success message in the form page

Admin side I submit form to admin-post.php. I want to print success message in the bottom of the form. Iam new in wordpress what i did shown below.

admin.php?page=add-products form code

 form action="?php echo admin_url('admin-post.php') ?" method="post"
                table
                input type="hidden" name="action" value="add_product_from_admin"
                trtdName/tdtdinput type="text" name="pr_name" id="pr_name"/td/tr 
    trtd colspan="2" align="center"input type="submit" name="pr_submit" id="pr_submit" value="Save Products"/td/tr
                /table
            /form


    add_action( 'admin_post_add_product_from_admin', 'add_product_into_data_base' );



function add_product_into_data_base() {
    //some database operations
wp_redirect(admin_url('admin.php?page=add-productsmessage=success'));
}

Topic notifications forms plugins Wordpress

Category Web


You need to pass the variable and its value in GET method to display the success message which you're already doing.

Now, in your PHP file, display a message based on the GET parameter and its value.

if($_GET['message'] == 'success'){ 
  //display your message 
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.