Skip Navigation

[Resolved] Using cred_save_data with generic multiselect field array output

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 1 year ago.

Assisted by: Waqar.

Author
Posts
#2657877
Screenshot 2023-10-28 at 07-42-17 Edit Job “CRED Auto Draft eb05c31fe1275750f27d1a76ed7f6f98” ‹ pdb ICM staging — WordPress.png
Screenshot 2023-10-28 at 07-39-49 testpage – pdb ICM staging.png

I’m trying to establish how to save form data output from a ‘multiselect’ generic field. My case appears to be the same as that described in this thread: https://toolset.com/forums/topic/cred-generic-field-not-saving-data/

At present, the only result I get is a saved value of ‘Array.’

Attached screenshots show the test form in use and the saved data result.

The relevant portion of the form looks like this:

<div class="form-group">
	<label for="wpcf-languages-select-test-value">languages select test</label>
	[cred_generic_field type='multiselect' field='wpcf-languages-select-test-value']
	{
	"required":0,
	"options":[ [wpv-view name='languages-json-list'] ],
	"persist":1
	}
	[/cred_generic_field]
</div>

The cred_save_data hook looks like this:

function test_form_data($post_id,$form_data) {
	if (isset($_POST['wpcf-languages-select-test-value'])) {
		$arr = $_POST['wpcf-languages-select-test-value'];
		$str = join(", ",$arr);
		add_post_meta($post_id, 'wpcf-languages-select-test-value', $str, true);
	}
}
add_action('cred_save_data_1070','test_form_data',10,2);
#2658373

Hi,

Thank you for contacting us and I'd be happy to assist.

To fix this, you can remove the 'persist' line from your generic field's code:


"persist":1

With 'persist' set to '1' the form saves the field's value as it is, which is in array format. Without it, the custom code attached to the 'cred_save_data' hook will be used to save the value, which is a comma-separated string.

regards,
Waqar

#2658423

That was it! Thank you, Waqar.