Success Message on Front End Submission
-
Hi, Any advice appreciated on getting a success message on front-end submission.
I am outputing a single meta-box as per this guide: https://github.com/WebDevStudios/CMB2/wiki/Bringing-Metaboxes-to-the-Front-End
And I’ve kept the array param for my new_cmb2_box ‘save_fields’ as true. So it saves automatically and works fine. I now want to show a successfully submitted message on submit.
I saw in the WebDev Studio post on FE submission, that they have a success message. But that involves writing a new submission function and disabling the save_fields option.
I’ve repurposed that function a bit to show errors, but was wondering if there is a simple way to check for post submission to complete my function?
You’ll see in my function that I only output errors. Any ideas here (or if this is possible without setting the save_fields to false and managing the submission through the function.
Perhaps this could also be modified to redirect as well. As I saw was possible in the CMB2 snippets page… Hope that explains what I’m doing enough and thanks for help.
function wds_handle_frontend_new_post_form_submission( $cmb, $post_data = array() ) { // If no form submission, bail if ( empty( $_POST ) ) { return false; } // check required $_POST variables and security nonce if ( ! isset( $_POST['submit-cmb'], $_POST['object_id'], $_POST[ $cmb->nonce() ] ) || ! wp_verify_nonce( $_POST[ $cmb->nonce() ], $cmb->nonce() ) ) { return new WP_Error( 'security_fail', __( 'Security check failed.' ) ); } if ( empty( $_POST['gift_description'] ) ) { return new WP_Error( 'post_data_missing', __( 'Gift Description is Empty.' ) ); } if ( empty( $_POST['site_admin_first_email'] ) ) { return new WP_Error( 'post_data_missing', __( 'Welcome Email is Empty.' ) ); } // Do WordPress insert_post stuff // Check if post submitted and return true return $new_submission_id; /* * Redirect back to the form page with a query variable with the new post ID. * This will help double-submissions with browser refreshes */ // wp_redirect( esc_url_raw( add_query_arg( 'post_submitted', $new_submission_id ) ) ); // exit; }
- The topic ‘Success Message on Front End Submission’ is closed to new replies.