Skip Navigation

[Resolved] conditional cred fields defualt values not submitting when hidden

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

Problem:
conditional cred fields default values not submitting when hidden with Toolset Form

Solution:
You can use the Toolset Form's hook: cred_before_save_data
in order to assign the default value based on your conditional selection of Form group for form fields.

You can find the proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/conditional-cred-fields-defualt-values-not-submitting-when-hidden/#post-1965405

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

This support ticket is created 3 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.

Our next available supporter will start replying to tickets in about 1.02 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by stuart 3 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#1964843

I am not sure if this is a bug or just not supposed to work this way, however, something isn't working right with CRED conditional fields.

I have a conditional field that houses a bunch of other fields, Generic and standard Type fields - its closed by default.

In these fields, I have default values that are set by types fields... now, when I submit the form and the conditional is closed they default values do not populate the custom post type.
When the conditional is open they do submit?

The way I have this setup:

CRED:
[credform]
Name: [types field='first-name' item="[types usermeta='profile-id' current_user='true'][/types]"][/types] [types field='last-name' item="[types usermeta='profile-id' current_user='true'][/types]"][/types]
<br>
Phone: [types field='phone-number' item='[types usermeta='profile-id' current_user='true'][/types]'][/types]
<br>
Email: [wpv-user field="user_email"]
<br>


[cred_generic_field type='checkbox' field='edit-data']
{
"required":0,
"default":"1",
"label":"<b>Edit details</b>"
}
[/cred_generic_field]
[cred_show_group if="( $(edit-data) eq '1' )" mode="fade-slide"]
<div class="form-group">
		<label>[cred_i18n name='applicant-first-name-label']First Name[/cred_i18n]</label>
[cred_generic_field type='textfield' field='f-name' class='form-control' output='bootstrap']
{
"required":1,
"default":"[types field='first-name' item="[types usermeta='profile-id' current_user='true'][/types]"][/types]"
}
[/cred_generic_field]
	</div>
	<div class="form-group">
		<label>[cred_i18n name='applicant-last-name-label']Last Name[/cred_i18n]</label>
[cred_generic_field type='textfield' field='l-name' class='form-control' output='bootstrap']
{
"required":1,
"default":"[types field='last-name' item="[types usermeta='profile-id' current_user='true'][/types]"][/types]"
}
[/cred_generic_field]
	</div>
	<div class="form-group">
		<label>[cred_i18n name='applicant-phone-label']Phone[/cred_i18n]</label>
[cred_field field='applicant-phone' force_type='field' required="true" class='form-control' output='bootstrap' value="[types field='phone-number' item='[types usermeta='profile-id' current_user='true'][/types]'][/types]"]
	</div>
	<div class="form-group">
		<label>[cred_i18n name='applicant-email-label']Email[/cred_i18n]</label>
[cred_field field='applicant-email' force_type='field' required="true" class='form-control' output='bootstrap' value='[wpv-user field="user_email"]']
	</div>

[/cred_show_group]
	[cred_field field='form_messages' class='alert alert-warning']
	[cred_field field='form_submit' output='bootstrap' value='Apply' class='btn btn-primary btn-lg']
[/credform]

I use CRED save data on the generic fields.

Changing to a Boostrap Toggle work in both closed and open, so I can do this ... just thought Id log it 🙂

#1965021

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Do you mean that when you save the form the default values for the generic fields are not get saved?

Lets say for example:

[cred_generic_field type='textfield' field='f-name' class='form-control' output='bootstrap']
{
"required":1,
"default":"[types field='first-name' item="[types usermeta='profile-id' current_user='true'][/types]"][/types]"
}
[/cred_generic_field]

For the above field - the value does not get saved?

do you have a field "f-name" created using Types plugin or you want to save the default value with the generic field name "f-name"?

#1965235

Hi there Minesh, not quite.

the default values don't get saved ONLY when the conditional box is closed, e.g when they are not visible.

As soon as I make them visible using the conditional - e.g visible as fields in the browser with the default values showing do they then get saved on submission.

#1965257

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

But I would like to know is it for only generic fields or its also applicable to normal types field.

It seems its because when the conditional block is closed - the fields will be hidden and does not get posted. But I can tell you or offer you workaround once I see the things in action.

Can you please share problem URL where you added the form and tell me what are the field names that does not get saved.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1965377

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Thank you for sharing the information.

But I'm afraid that the admin access details you shared is not working at this end. Can you please share working admin access details. The member access details works.

I have set the next reply to private which means only you and I have access to it.

#1965405

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now.

I've added the following hook that will help to set ehe default values when the "Edit details" checkbox is not checked:


function func_adjust_default_values( $form_data ){
 
    if ( 950 == $form_data['id'] ){        
      global $current_user;
      if(!isset($_POST['edit-data'])){
        $profile_id = get_user_meta($current_user->ID,'wpcf-profile-id',true);
        $f_name = get_post_meta($profile_id,'wpcf-first-name',true);
        $l_name = get_post_meta($profile_id,'wpcf-last-name',true);
        $phone = get_post_meta($profile_id,'wpcf-phone-number',true);
        
        $_POST['f-name'] =  $f_name;
        $_POST['l-name'] =  $l_name;
        $_POST['wpcf-applicant-phone'] =  $phone;
        $_POST['wpcf-applicant-email'] =  $current_user->user_email;
        
      }
       
    }
}
add_action('cred_before_save_data','func_adjust_default_values',10,1);
#1965429

Works perfectly, thanks Minesh... a little tricky that one.