Skip Navigation

[Resolved] append new updates into a multiline field

This support ticket is created 3 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 2 replies, has 1 voice.

Last updated by manishB-2 3 years, 4 months ago.

Assisted by: Jamal.

Author
Posts
#2143759

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.

#2143837
#2143979

Hi Jamal,
Waiting for your response. Kindly help me debug and fix the issue.

Thank you

#2144267

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);