plugins – How to redirect to same page after form submission

Question

I am working on a plugin where a new page template is created on plugin activation. The template has a form for user input.

<form action="" method="post">
    <textarea name="question"></textarea>
    <input type="submit" name="submit_question">
</form>

Value is properly stored in following way:

if ( isset( $_POST[ 'submit_question' ] ) ) {
    $wpdb->insert(
        $table_name,
        array( 'question' => $question,
               'created_at' => $created_on
        ),
        array( '%s', '%s' )
    );
}

The issue is, if the page is reloaded after form submission, its restoring the values again. How can I clear the values after submission? Or redirect properly? I tried some solutions (e.g. wp_redirect ) but not getting any result. Please help.

0
Ahsan 2 months 2021-07-23T12:32:57-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse