Skip Navigation

[Resolved] Can't explain select default (bug?)

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

Last updated by Minesh 1 month, 1 week ago.

Assisted by: Minesh.

Author
Posts
#2689672

Hi,
In a form I have a custom field select with the following options: 0,1,2,3,4,5+ with 0 set as default.
- after submitting the form, if I open the post in the (classic) editor I can see that the field is set to 0 (correct), but
- if I test the value in a conditional it returns blank
- also on the dasboard page for the Custom Post the field value displayed is blank
- if I open and save again the custom post in the editor then the field value is "really" saved to 0, indeed the conditional now returns 0, but on the dasboard page still blank is displayed!

Is this a bug or is it normal ? my expectations are that if the custom field is defaulted to 0 it should get that value immediately upon saving the form ...
Please explain.
thanks
Regards
Nicola

#2689713

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Using zero as value sometimes shows intermittent results.

Can you please share problem URL and admin access details and tell me at what section you want to display what or what is your expected results.

Once I review the issue I will be able to guide you in the right direction.

*** 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 have set the next reply to private which means only you and I have access to it.

#2689754

Minesh
Supporter

Languages: English (English )

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

I thought to use the following snippet to force 0 upon submit, but I need to add a test "only if the field is empty" and I don't know the syntax ....

add_action('cred_save_data', 'set_nbr_of_required_bands',10,2);
function set_nbr_of_required_bands($user_id, $form_data)
{
if ($form_data['id']==7089) ?????? AND required-bands eq "" ?????
{
$bands = 0;
update_user_meta($user_id, 'required-bands', $bands);
}
}
====>
Where can I see the field "required-bands" on the form the following form hidden link?

#2689755

The field is not on the form because it doesn't need user input, is defaulted to 0 (so I thought ....)

#2689756

To be more precise: this form is reserved to "normal" users, they don't need to use this field so I defaulted to 0. Pub_managers use a different form where this field is displayed and they can select the nbr of bands.

#2689759

Minesh
Supporter

Languages: English (English )

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

Instead of storing the zero (0) what if you try to save the empty value.

Can you please tell me where with what custom field group I can see the custom field "required-bands" you configured?
- Is it a post field or user field?

#2689762

The CPT is Events, field required-bands (Nbr of requested bands)

I am not sure I can use blank instead of 0 because the same feld is used by pub_managers as well with their own form. If I use a conditional testing blank, when pub_managers select the option 0 the conditional would not test it correctly. I'd prefer to force 0 with the snippet used in this form only.

#2689763

Minesh
Supporter

Languages: English (English )

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

Can you please try to use the following hook to set the default value as 0 for the field "requested-bands":

The form with ID 7089 I do not see the field "requested-bands" is added to that form so there is no need to check if the field ""requested-bands" is available or not with form submit data.

add_action('cred_save_data', 'set_nbr_of_required_bands',10,2);
function set_nbr_of_required_bands($post_id, $form_data) {
if ($form_data['id']==7089) {
    $bands = 0;
    update_post_meta($post_id, 'wpcf-requested-bands', $bands);
}
}
#2689771

Hi Minesh,
ok, this works, you are right I don't need to test if the field is blank. We can consider closed this ticket even though the issue with the default setting 0 still exists, please inform your developers.

>>>Meanwhile you have access to my site<<<, I'd like to let you know about what below.
Some time ago you helped me with this filter:
https://toolset.com/forums/topic/help-on-conditional-date-lag-test/
Unfortunately on Jan 1st, 2024 all classifieds created in Oct, Nov and Dec 2023 (by 90 days before today) disappeared because filtered out by the filter due to the year change ! I tried to remove the "current year" part of the filter, but it doesn't work as expected anymore. BTW, at the time I set this filter in a classic view, later I changed the view to a (block) archive, but in the archive editor I don't see any place where I can set a filter like this ...
thanks
If you want split this issue please do it.
thanks
Nicola

New threads created by Minesh and linked to this one are listed below:

https://toolset.com/forums/topic/split-cant-explain-select-default-bug-year-change-issue/

#2689780

Minesh
Supporter

Languages: English (English )

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

I've split the ticket with your new question and you're welcome to close this ticket. Regarding the zero not working - please open a new ticket if required.

nicolaS-3 confirmed that the issue was resolved on 2024-03-28 12:40:44.
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.