Skip Navigation

[Resolved] opposite of cred_save_data

This thread is resolved. Here is a description of the problem and solution.

Problem:

Setup default value in Toolset Forms shortcode [cred_generic_field].

Solution:

You can setup the default value of shortcode [cred_generic_field] with parameter "default", for example:

https://toolset.com/forums/topic/opposite-of-cred_save_data/#post-1883479

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred_generic_field

This support ticket is created 4 years, 1 month 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 3 replies, has 2 voices.

Last updated by jamesR-13 4 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1883207

I have a cred generic field called 'unitstatusselect' that updates a text field called 'unitstatus' using cred_save_data.

This is working as expected, but when I load a post for editing, the generic field always shows as 'not set' even though a value is set in the text field. How can I make the text field value display in the generic field when I load the editing form?

I have tried setting persist:1 on the generic field, and that keeps the selected value displaying in the editing form, but the value is no longer updated on form submit.

Please advise.

#1883479

Hello,

I assume we are talking about Toolset Forms shortcode [cred_generic_field], see our document:
https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred_generic_field

You can setup the default value of shortcode [cred_generic_field] with parameter "default", for example your custom field is using slug "wpcf-my-field", you can get the field value with shortcode:
[wpv-post-field name="wpcf-my-field"]
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-field

And pass above value to shortcode [cred_generic_field], like this:

[cred_generic_field field="wpcf-my-field" type="text" class=""]
 {
...
  "default":'[wpv-post-field name="wpcf-my-field"]',
...
 }
[/cred_generic_field]
#1883841

That was exactly what I needed! I guess that should have been obvious to me! Thank you!

One problem though, now my edit post form cred_save_data function doesn't seem to update the text field from the generic field.

Here's my functions.php code:

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

if ($form_data['id']==344)
{
error_log('cred save data, form 344');
if (isset($_POST['unitstatusselect']))
{

update_post_meta($post_id, 'wpcf-unitstatus', $_POST['unitstatusselect'], true);
}
}
}

#1884095

My issue is resolved now. Thank you!