Skip Navigation

[Resolved] Copying dynamic select field and saving value into another field for display

This support ticket is created 4 years, 10 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by Minesh 4 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#1536483

Tell us what you are trying to do?
In an edit post form I would like to save a value from a dynamic select field into another field for display and storage purposes.

Is there any documentation that you are following?
I searched for a similar approach but could not find any documentation or help for this.

Is there a similar example that we can see?
Yes there are forms in place needing the change.

What is the link to your site?
Need to provide credentials as no public access at the moment!

#1536551
AstroFamilyStory-member-listing.png
AstroFamilyStory-member-edit-form.png

To elaborate further in the edit post form I have a country look-up select field from a third-party solution. I will need that value selected to be saved into the database. And then retrieved for display in the listings view. Please see the attached screenshot.

The idea here is that I could maybe use a second field into which I copy the selected value and upon saving the form can be retrieved.

#1537083

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

As I understand, you want to copy the "Select Different country of birth" field value to the field "Place of birth - country stored". If this is correct, then you can use the Form's API hook "cred_save_data":
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

For example:
- Please add the following code to your current theme's functions.php file
Or
- You can add the following code to the "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

add_action('cred_save_data', 'func_update_contry_field',10,2);
function func_update_contry_field($post_id, $form_data){
    // if a specific form
    if ($form_data['id']==9999){
        if (isset($_POST['field-slug-current-country']))
        {
            // add it to saved post meta
            update_post_meta($post_id, 'filed-slug-to-store-country', $_POST['field-slug-current-country']);
        }
    }

Where:
- Please replace 9999 with your original form ID
- replace the correct field slugs with "field-slug-current-country" and "filed-slug-to-store-country"