Hi I have a multiple field called "wpcf-protocols" and I want to add new line each time when a generic field is filled or if generic field doesnt work then I i can create a another single line field "wpcf-new-protcol" and the inserted value can be appened to multiline field with Current Logged in user and modified time.
Actually, I am just looking for an option that can take input and just process to function to execute and save to multiline field in new line but do not show any value on that field where we need to add new values.
The edit form, will not include a field "wpcf-protocols". this "wpcf-protocols" will only be available in post. but in Edit form we can use any field like a generic field or any other post field but need to make sure that when someone open the edit form, then this field "(to take new input)" doesn't display any existing value.
Hi Jamal,
Waiting for your response. Kindly help me debug and fix the issue.
Thank you
I had been inspecting the code on my own and foun that code was not triggered if i add it on function.php file but when i added the same by creating a new plugin then it worked.
function my_save_data_action($post_id, $form_data)
{
// if a specific form (change 1234 with your CRED ID)
if ( $form_data['id'] == 1671 )
{
// get the submitted value from the generic field
$generic_field_text = isset( $_POST['nprotocol'] ) ? $_POST['nprotocol'] : '';
$current_person = isset( $_POST['current_user'] ) ? $_POST['current_user'] : '';
$current_datet = isset( $_POST['date_time'] ) ? $_POST['date_time'] : '';
// If no value provided, just exit.
if ( sizeof( $generic_field_text ) == 0 ) return;
//get your exisitng Post Custom field multi line value
$existing_protocol = get_post_meta($post_id, 'wpcf-protocols', true);
$format = get_option( 'date_format' );
$the_time = wp_date( get_option( 'date_format' ) );
//construct your new multiline content
$new_field_text = $existing_protocol . '<br />' . $generic_field_text . 'By- ' . $current_person . ' - ' . $current_datet;
//update the field
update_post_meta($post_id, 'wpcf-protocols', $new_field_text);
}
}
add_action('cred_save_data', 'my_save_data_action',10,2);