Skip Navigation

[Resolved] My form updates a CPT entry, but I can't force a value into a preexisting field

This support ticket is created 8 years, 2 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 8 replies, has 2 voices.

Last updated by eduardoM 8 years, 2 months ago.

Assisted by: Shane.

Author
Posts
#420392

I am trying to: to make the form fill a field with a new value for field "status-cover". Despite all my efforts, the form always keep the original value loaded; since it'll be a hidden field, the user cannot type the new value. I must define it.

I visited this URL: hidden link

I expected to see: in the last form field, the value should be "ongoing"

Instead, I got: the existing value, "pending-author-questionnaire"

I tried to force the default value in the shortcode:

[cred_field field='status-cover' post='ebook' value='new-value-that-will-show-but-wont-save' urlparam='']

I tried copying the html output and putting it in the CRED post form configuration

<div class="js-wpt-field-items js-wpt-repetitive wpt-repetitive" data-initial-conditional="" data-item_name="textfield-wpcf-status-cover">
<input type="text" id="cred_form_120_1-textfield-3-1469716231" name="wpcf-status-cover" value="new-value-that-will-show-but-wont-save" class="wpt-form-textfield form-textfield textfield" data-wpt-type="textfield" data-wpt-id="cred_form_120_1_cred_form_120_1-textfield-3-1469716231" data-wpt-name="wpcf-status-cover" />
</div>

None of the above worked. The form update only the fields altered by the user itself; if I kept the field read-only, it wont save the value I've informed, it'll rather keep the original one already stored.

#420481

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Eduardo,

Thank you for contacting our support forum.

Could you confirm that what you are trying to do is adding a value to a custom field using CRED?

Please let me know.

Thanks,
Shane

#420486

Hi Shane. Yes, it is.

#420487

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Eduardo,

Then you can simply do this by going to Add Generic Field and then add the appropriate field type then give it this slug "status-cover"

This should allow you to populate the field.

Please let me know if this helps.
Thanks,
Shane

#420492

Just tried, and this don't solve the problem. I need this new value to be stored, not just to be replaced in the form. Otherwise it'll be useless.

I'll explain again.

I have a custom post type called Book. I created this Cred update form, to fill some fields and store them (all of them).

But one of those fields is a status field, that starts in this form with the value "pending-author-questionnaire".

What I need this Cred form to is to change this value to "ongoing", after my client press "submit". None of the methods I tried above, and yours too, helped me accomplish this simple task.

What should I do to update this field with a different value?

#420493

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Eduardo,

What kind of field is the status field?

Could you provide me with a screenshot of it in Types so that I can see how it has been setup.

We should be able to achieve this by using a hook.

Thanks,
Shane

#420495
status-cover.JPG

I'ts a single-line.

#420506

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Eduardo,

Thank you what you can do is add the following to your functions.php file.

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==12)
    {
     
            // add it to saved post meta
            add_post_meta($post_id, 'wpcf-status-cover', "ongoing", true);
        
    }
}

What you need to do is change the 12 to the id of your Cred form.

Please let me know if this helps.

Thanks,
Shane

#420513

Thank you Shane!

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.