Skip Navigation

[Resolved] Save generic select field (the label and not the value) in another cred field

This support ticket is created 3 years, 8 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: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by Lara 3 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#2032443

Tell us what you are trying to do?

I have a generic select field in a CRED form. I get the options from a shortcode. Works everything fine so far. I use the generic select field to connect the newly created post with another post. Additional to that, I need to save the "label" of the choosen option in another single line input field. I know how I can save the value of the option - but unfortunately I need the label and not the value. Any ideas?

I use cred_save_data hook and that's the code so far...
update_post_meta( $post_id, 'wpcf-activity', $_POST['select-activity']['label'] ); ---> it doesn't work 😉

Is there any documentation that you are following?
Something similar to this, just that I use it in a slightly different context:
https://toolset.com/forums/topic/assigning-the-post-to-a-user-on-the-front-end/

Is there a similar example that we can see?
In the documentation, but without the "label" problem. They only access the value ...

What is the link to your site?
hidden link

#2032845

Hello,

I think there is a misunderstanding, after user submit the form, in server side, you can get only the select option value, you can not get the option label setting, so you consider to move option label value into select option value settings.

More help:
hidden link

#2032851

The thread you mentioned above:
https://toolset.com/forums/topic/assigning-the-post-to-a-user-on-the-front-end/

It is for changing the post author with user's ID, so after the post author is changed, in the post content, you can display post author nickname with shortcode:
[wpv-post-author format='meta' meta='nickname']
So I don't think you need to pass user's nickname to your custom PHP codes.

#2036999

...

#2037063

Many thanks Luo and many appologies for the delay.
I found a workaround.
My issue is resolved now. Thank you!

Workaround:

add_action('cred_save_data', 'terminserie_erstellen_mad',10,2);
function terminserie_erstellen_mad ($post_id, $form_data) { 

// if a specific form
$forms = array( 47490 );
   
if (in_array($form_data['id'], $forms)) {
  
//get the value of the field, that is shown in the generic dropdown as "label" from the corresponding activity post
// the $_POST['generic-select-field'] represents the id of the corresponding activity post
$label = get_post_meta($_POST['generic-select-field'],'wpcf-acitivty-name',true);

// update the field in the newly created post with the value from the label
update_post_meta( $post_id, 'wpcf-field-that-should-contain-label-value', $label);

//connect the newly created post with the corresponding acitivity post, where "acitivity-rask" is the relationship slug 
toolset_connect_posts( 'acitivity-rask', $_POST['generic-select-field'], $post_id);  
}
}