Support Forum
Support › MB Frontend Submission › Holding fields for review
I am thinking of adding a system where certain fields need to be manually reviewed before they're applied.
Any chance you could help me with a few questions?
Which hook should I use to intercept the submit?
(using custom tables) Where to store the data after approved other than my custom tables?
-- This question is mostly regarding tables like wp_postmeta. Do I need to put any changes in any of those WordPress tables, or can I just put them directly into the custom tables wp_my_custom_table
Any other tips on how this could be done (optional)?
Basically, if someone changes their first and last name, I want to throw it in (hypothetically) wp_pending_changes table. I can create an admin page that lists anything on that table. If approved, it overwrites my custom table and wp_pending_changes is cleared.
But if only one question can be answered, it would be the hook to use to intercept the submit! Thanks!
Hello Amy,
To manually review the post before publishing it, you can simply use the attribute post_status
of the frontend form shortcode [mb_frontend_form id="field-group-id" post_fields="title,content" post_status="pending"]
.
If you want to do something after saving the post, please try to use the hook rwmb_frontend_after_save_post
or rwmb_frontend_after_process
Hi Peter, thank you. It would have to be the latter because some fields will be allowed to process. I'll check out those hooks 🙂
Oh, and the save-to part is fairly important as well. I am using custom tables. When a change is approved, do I just push it to the custom table field, or do I also need to push it to any WordPress tables like wp_postmeta?
Thanks!
After a post is submitted successfully on the frontend, the custom field value is already saved to the custom table (if you choose to save the custom table), not waiting to approve. Then it is not possible to move the field value to the default table wp_postmeta
because the field is registered to get the value from the custom table.
So, I did the after_save_post action with fields, and just got these fields:
` [fields] => Array
(
[0] => post_title
[1] => post_content
[2] => post_excerpt
[3] => post_date
)
Is there a way to access the actual custom fields on the frontend submission?
You can access the field value on submitted through the global variable $_POST. For example: $_POST['field_id']
Thank you, it has worked well. I do need one more thing, however.
Could you tell me how to stop the field from actually pushing to database? As I mentioned, I want to hold certain fields for review, so I tapped into 'rwmb_frontend_before_save_post' and have roughly this:
$old = rwmb_get_value($key, '', $id);
$new = $_POST[$key];
if $old !== $new {
// Here is where I want to take the field and push it off into it's own custom table but NOT save it to the live site.
}
Is there a command to prevent $new from saving if there is a change? Thanks!
There is no way to prevent saving the field on this action hook. I think you can delete the field value after that by using the function delete_post_meta().
Or use the field setting save_field
and set it to false
to prevent saving the field value. Read more on the documentation https://docs.metabox.io/field-settings/
I was worried you were going to say that, so I thought of an alternative. Seeing as there are only a few fields that will be forced to remain the same until review (2-3 out of 30 or so fields), what I may do is just:
- Save changes to a new table
- Overwrite current table with old data for the 3 fields
If changes are approved, overwrite the live table with the changes
So basically, as a workaround, it'll change it and then instantly revert back to old all in same save. Is that ideal? No. But it is better than re-writing a frontend dashboard without metabox which would take significantly longer than this kludge lol