I’m working on the same project for which I sought help in two previous tickets a few weeks ago, <a href="https://toolset.com/forums/topic/using-cred_save_data-with-generic-multiselect-field-array-output/">‘Using cred_save_data with generic multiselect field array output’</a> and <a href="https://toolset.com/forums/topic/generic-select-form-field-from-repeatable-field-group-one-to-many-relationship/">‘Generic select form field from repeatable field group, one-to-many relationship’</a>.
The difficulty I’ve run into now is related, but the case seems simpler, if anything. I’m building out the user-facing elements for a post-type connected to those I was working on earlier, and I’m using generic select form fields drawing on repeatable-field-group data from a parent in a manner essentially the same as done with success elsewhere in the project. My generic select fields in the current instance display query data correctly, and cred_save_data hook usage is effectively copy of other working functions serving the same purpose elsewhere. In the current instance, however, the generic field form data isn’t getting saved.
Below, the relevant parts of the two form with respective corresponding functions, mostly identical, as I have them at the moment.
I’ve experimented with producing the selection list in different ways, but this seems to have no bearing on the problem. I’ve included "persist":1 and removed it without effect. I’ve also tried variations of the save functions using add_post_meta() and update_post_meta(), again apparently without effect.
<div class="form-group">
<label for="%%FORM_ID%%_task-assignable-worker-a">[cred_i18n name='task-assignable-worker-a-label']Assignable Worker A[/cred_i18n]</label>
[cred_generic_field type='select' field='task-assignable-worker-a' class="form-control"]
{
"required":0,
"default":[ [types field="task-assignable-worker-a" output="raw"][/types] ],
"options":[ [wpv-post-body view_template='filtered-worker-selection'] ],
"persist":1
}
[/cred_generic_field]
</div>
function jobtask_update_worker_select_a( $post_id ) {
if ( isset( $_POST[ 'wpcf-task-assignable-worker-a' ] ) ) {
$new_val = $_POST[ 'wpcf-task-assignable-worker-a' ];
update_post_meta( $post_id, 'wpcf-task-assignable-worker-a', $new_val );
}
}
add_action( 'cred_save_data_1531', 'jobtask_update_worker_select_a', 10, 2 );
and
<div class="form-group">
<label for="%%FORM_ID%%_task-street-address">[cred_i18n name='task-street-address-label']Job Task Street Address[/cred_i18n]</label>
[cred_generic_field type='select' field='task-street-address' class='form-control']
{
"required":0,
"options":[ [wpv-view name="task-addresses-selection-container"] ]
}
[/cred_generic_field]
</div>
function jobtask_update_address_select( $post_id ) {
if ( isset( $_POST[ 'wpcf-task-street-address' ] ) ) {
$address = $_POST[ 'wpcf-task-street-address' ];
update_post_meta( $post_id, 'wpcf-task-street-address', $address );
}
}
add_action( 'cred_save_data_1587', 'jobtask_update_address_select', 10, 2 );