Skip Navigation

[Resolved] 2 same mandatory field in the same cred

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

Problem:
make 2 same identical fields with the mandatory field and validate in the same cred form

Solution:
You can add another field using Generic field and later once it passes the validation, use the Forms hook cred_before_save_data to assign the value to original field "wpcf-contraente".

You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/2-same-mandatory-field-in-the-same-cred/#post-1141247

Relevant Documentation:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data
=> https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/

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

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 7 replies, has 2 voices.

Last updated by culturaI 5 years, 5 months ago.

Assisted by: Minesh.

Author
Posts
#1139804

Hello i setup 2 radio fields:
1. radio field: cliente (values "privato" or "business")
2. simple text 1 row: codice-fiscale-o-partita-iva (mandatory field)

I want to obtain this result:

if radio field selected is "privato"
label: "codice fiscale" - input field "codice-fiscale-o-partita-iva"

if radio field selected is "business"
label: "partita iva" - input field "codice-fiscale-o-partita-iva"

I'm using correctly conditional show group and mandatory check in my custom fields, effectively is working all good.

My problem is that using twice in same cred field "codice-fiscale-o-partita-iva" this field is not mandatory anymore.
If i use only one time is working good.

#1140276

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - I review your requirement and I can see that you just want to change the label according to your selection - is it correct? If yes:

Could you please share problem URL where you added your form and access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) 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 would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

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

#1141247

Minesh
Supporter

Languages: English (English )

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

Well - I think there is only solution here is to add a generic field with another name.

For example - the field name should be "wpcf-contraente1" and set to be required on your form here:
=> hidden link

 [cred_generic_field type='textfield' field='wpcf-contraente1']
{
"required":1,
"default":""
}
[/cred_generic_field]

And later once it passes the validation, use the Forms hook cred_before_save_data to assign the value to original field "wpcf-contraente".
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data

For example:

add_action('cred_before_save_data', 'func_assign_field_value',10,1);
function func_assign_field_value($form_data)
{
    // if a specific form
    if ($form_data['id']==62)
    {
        if (isset($_POST['wpcf-contraente1'])) {
          $_POST['wpcf-contraente'] = $_POST['wpcf-contraente1'];  
        }
    }
}
#1141563

Very interesting approach, i can add generic field on fly?
I mean i have not to create "wpcf-contraente1" on types custom fields?

#1141640

Minesh
Supporter

Languages: English (English )

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

Yes - you do not need to creare wpcf-contraente1 field with Types.

#1142548

Fantastic working good, great function.

Thanks Minesh!

#1142568

Minesh
Supporter

Languages: English (English )

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

Good to know. Please feel free to resolve the ticket.

#1143200

My issue is resolved now. Thank you!

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