Hi,
I have a post form to edit a post with different select fields. Also, I have different single line fields to save modified by name. I would like to save in modified by field the select field was modified by whom. For example if select field "a" was modified, I want to same in single line "a " who modified it. How this can be done?
If the edit form's ID is "123", the code for the function would look like this:
add_action('cred_before_save_data', 'my_before_save_data_action',10,1);
function my_before_save_data_action($form_data)
{
// if a specific form
if ($form_data['id']==123)
{
$post_id = $_POST['_cred_cred_prefix_post_id'];
$user_id = do_shortcode('[wpv-current-user info="id"]');
$post_meta = get_post_meta( $post_id );
// field "wpcf-book-radio-1"
if($post_meta['wpcf-book-radio-1'][0] != $_POST['wpcf-book-radio-1']){
$_POST['wpcf-book-radio-1-hidden'] = $user_id;
}
// field "wpcf-book-radio-2"
if($post_meta['wpcf-book-radio-2'][0] != $_POST['wpcf-book-radio-2']){
$_POST['wpcf-book-radio-2-hidden'] = $user_id;
}
}
}
Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors: https://toolset.com/contractors/
Thank you for your reply. I have modified the code and added to the functions.php. However, when a user is modifying one filed the user name will be stored as they modify all fields. Please advise.
Using the access details that you shared in the chat, I'm not able to access the WordPress admin area.
Can you please share the access details of two different users who can modify the fields in this form? Please also share the exact code snippet that you've used for this.
I noticed that in the hidden fields, a default value is being set using the "[wpv-current-user]" shortcode.
( screenshot: hidden link )
We need the originally saved value from the database in these fields so that our custom function can perform the comparison and save the current user's ID if a particular field is modified.
Please remove that "[wpv-current-user]" shortcode from those hidden fields and only use: value=''
Important note: If you still feel that the hidden fields are not working properly, please include full steps and information about the users, that you used for the testing.