nicokiri
(Bob LE)
February 13, 2024, 10:07am
1
Hi,
I use “chained selects” for my user to select :
1.1 The number of the “county”
1.2 The name of the city
1.3 Postcode
This is great like this because it avoids error in spelling of the city, or in the number of the postcode (according to the city)
But the postcode is unique for each city. How to hide 1.3 field from user please, but still saving the right Postcode when the user submits ?
Thanks a lot !
chrishajer
(Chris (Gravity Forms))
February 14, 2024, 12:33am
2
Will this work to autoselect the only option in the Postcode drop down, if there is only one?
<?php
/**
* Gravity Wiz // Gravity Forms Chained Selects // Auto Select Only Option
* https://gravitywiz.com/
*
* The Gravity Forms Chained Selects field requires you to manually select a value in each Drop Down
* even if there is only a single option available in that Drop Down. This snippet will automatically
* selected an option when it is the only option available.
*/
add_filter( 'gform_chained_selects_input_choices', function( $choices ) {
$choices = gfcs_auto_select_only_choice( $choices );
return $choices;
} );
function gfcs_auto_select_only_choice( $choices ) {
$choices[0]['isSelected'] = $choices[0]['isSelected'] || count( $choices ) <= 1;
if ( ! empty( $choices['choices'] ) ) {
$choices['choices'] = gfcs_auto_select_only_choice( $choices['choices'] );
This file has been truncated. show original
It will still be visible, but the user won’t need to select it manually.
An alternative option would be to use GP Populate Anything instead of Chained Selects. It supports populating into hidden fields.
We have an article on how to set up the chained selects. The only difference in your use case is that you would set one of the field’s Visibility setting to Hidden.
2 Likes
nicokiri
(Bob LE)
February 17, 2024, 10:40am
4
Hey Chris and Scott,
Great, thanks a lot, both, for your help !!
Have a nice week-end, and sorry for my late answer !