0

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.

1
1

Did you try to exit; after the wp_redirect()?

“Note: wp_redirect() does not exit automatically, and should almost always be followed by a call to exit;”

https://developer.wordpress.org/reference/functions/wp_redirect/

0

A common use of PHP_SELF variable is in the action field of the tag. The action field of the FORM instructs where to submit the form data when the user presses the “submit” button. It is common to have the same PHP page as the handler for the form as well.

<form action="<?php echo $_SERVER['PHP_SELF']; ?> " method="post">
    <textarea name="question"></textarea>
    <input type="submit" name="submit_question">
</form>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.