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);
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:
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
That was it! Thank you, Waqar.