Skip Navigation

[Resolved] CRED generic field not saving data?

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

Problem: I am using a generic field in my Form but it doesn't seem to save data into my custom field.

Solution: Be sure to use the correct slug. Types fields have a wpcf- prefix in the database, and a generic field should use the same prefix.

add_action('cred_save_data', 'my_save_data_action_choices',10,2);
function my_save_data_action_choices($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==34373)
{
if (isset($_POST['wpcf-roommate-preferences']))
{
// add it to saved post meta
$emails = $_POST['wpcf-roommate-preferences'];
$comma_separated = implode(",", $emails);
add_post_meta($post_id, 'wpcf-roommate-preferences', $comma_separated, true);
}
}
}

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This support ticket is created 4 years, 9 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.

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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by charleneK 4 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1505849

I have a CRED form that with two fields, an email field and a Generic field with options created by a view:

[credform]
[cred_field field='form_messages' class='alert alert-warning']
<div class="form-group">
<label>Person Making Choice</label>
[cred_field field='' force_type='field' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>Roommate Preferences</label>

[cred_generic_field type='multiselect' field='roommate-preferences' class='']
{
"required":1,
"default":[],
"persist":1,
"options":[[wpv-view name="matched-new"]]
}
[/cred_generic_field]
</div>
[cred_field field='form_submit' output='bootstrap' value='Submit' class='btn btn-primary btn-lg']
[/credform]

The view is:
[wpv-layout-start]

[wpv-items-found]

<!-- wpv-loop-start -->

<wpv-loop>

[wpv-item index=other]

{"value": "[wpv-post-field name='_billing_email']", "label": "[wpv-post-field name='_billing_first_name'] [wpv-post-field name='_billing_last_name']"},

[wpv-item index=last]

{"value": "[wpv-post-field name='_billing_email']", "label": "[wpv-post-field name='_billing_first_name'] [wpv-post-field name='_billing_last_name']"}

</wpv-loop>

<!-- wpv-loop-end -->

[/wpv-items-found]

[wpv-no-items-found]

{"value": "", "label": "No items found"}

[/wpv-no-items-found]

[wpv-layout-end]

The form is generated correctly, I can see the values when checking the HTML of the form. I'm using this form to create a new post of type "Shared Choices" which has two custom types fields "person-making-choice" and "roommate-preferences" The "person-making-choice" field is saved fine but for some reason the "roommate-preferences" is not saved. I'm sure I've missed something simple and obvious, but it's a mystery to me right now. thanks much++

#1505917

Hi, Types fields have a prefix of 'wpcf-' in the database, so your generic field should include that prefix as well:

[cred_generic_field type='multiselect' field='wpcf-roommate-preferences' class='']

Try that and let me know if the problem is not resolved.

#1505987

Ok, I"ve got output in the field, now, but it's "Array"

#1506049

Solved my issue: of course, it's in an Array as it's a checkbox with multiple results.

used this to implode the results and save to post.

add_action('cred_save_data', 'my_save_data_action_choices',10,2);
function my_save_data_action_choices($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==34373)
{
if (isset($_POST['wpcf-roommate-preferences']))
{
// add it to saved post meta
$emails = $_POST['wpcf-roommate-preferences'];
$comma_separated = implode(",", $emails);
add_post_meta($post_id, 'wpcf-roommate-preferences', $comma_separated, true);
}
}
}