Skip Navigation

[Resuelto] Hidden Fields Still Showing as Required

This support ticket is created hace 5 años, 4 meses. 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 2 respuestas, has 2 mensajes.

Last updated by Sean hace 5 años, 4 meses.

Assisted by: Waqar.

Autor
Mensajes
#1147408

Parent post type: Trip
Child post type: Attendee
I have a form that creates an Attendee based on the URL (coming from a particular Trip). This generally works fine. I am using cred_show_group to hide some fields based on the taxonomy of the parent:

[cred_show_group if="( '[wpv-post-taxonomy  type="triptype" format="slug" id="[wpv-search-term param="parent_trip_id"]"]' eq 'day-trip' )"]

This works, but when I submit something that doesn't use these hidden fields, I still get the js errors (and no helpful highlighting beyond there being 4 errors) that they are required. If I take out these fields entirely, it works.

I normally use wpv-conditional for this, but the same syntax doesn't work. Is a small shift in syntax the solution or do I have to try something wildly different?

#1147749

Waqar
Supporter

Languages: Inglés (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Sean,

Thank you for contacting us and I'll be happy to assist.

The conditional shortcode for forms ( [cred_show_group] ) is designed to work with the form field values and the validation function also can recognize whether a field should be ignored or not for validation when it is hidden based on a field's value.

In case the [cred_show_group] shortcode is using the values generated through other shortcodes or custom functions, you'll be able to hide the field, but validation will still show an error if that field is a required field.

To avoid this situation, I'll suggest the following steps:

1. Please add following code in your active theme's "functions.php" file, to register a new shortcode:


// check post's taxonomy
add_shortcode('check-parent-trip-tax', 'check_parent_trip_tax_fn');
function check_parent_trip_tax_fn() {
	if (!empty($_GET['parent_trip_id'])) {
		$value = do_shortcode('[wpv-post-taxonomy type="triptype" format="slug" id="'.$_GET['parent_trip_id'].'"]');
		if($value) {
			return $value;	
		}		
	}
}

The above code will register a new shortcode [check-parent-trip-tax], which gets the URL parameter "parent_trip_id" and returns the slug of the term attached to that post in "triptype" taxonomy.

2. Next, you can add the following code to register a new hidden generic field, which gets its value from our newly registered shortcode:


[cred_generic_field type='hidden' field='field-check']
{
"default":"[check-parent-trip-tax]"
}
[/cred_generic_field]

Note: this generic field code can be added in the form, just before the conditional field's block.

3. After that, you'll be able to use the value of this hidden field in your condition, like this:


[cred_show_group if="( $(field-check) eq 'day-trip' )"]
......
[/cred_show_group]

I hope this helps.

regards,
Waqar

#1148186

That did the trick. Many thanks.

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