Skip Navigation

[Resolved] Displaying Default Value of CRED form field on template

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

Problem:

My understanding is that if the user leaves a field blank, the Default Value would be used instead - in other words, the field can not be blank or zero if Default Value has a value.

Solution:

The default value works only for when you create the post, it will pre-fill the phone number field with default value "N/A", your user can clear the field value to blank.

After save post, the Types shortcode [types field='phone-number'][/types] will display the value from website database, since it is empty, it will output blank value.

In your case, you might consider to use [wpv-conditional] shortcode to check "Phone Number" field's value, if it is blank/empty, then display text "N/A", for example:

https://toolset.com/forums/topic/displaying-default-value-of-cred-form-field-on-template/#post-1377749

Relevant Documentation:

https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/

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

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/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by stevenT-5 4 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#1377617
Screen Shot 2019-11-06 at 4.22.21 PM.png

Hi,
On the screen for creating custom form fields, there are a couple handy functions, Placeholder and Default Value. My understanding is that if the user leaves a field blank, the Default Value would be used instead - in other words, the field can not be blank or zero if Default Value has a value. This is the only way that makes sense to me why this function exists.

To make Default Value work the way it should, I expect the front end template to display that default value when user did not fill in anything. In my case, the front end template still shows nothing and displays content only if the user fills in something for that field. So the way it's working now, the Default Value function is useless. Pls see attached screen. Note that I did fill in the Default Value field in the custom field screen for testing purposes.

#1377669

Hello,

There are some misunderstandings:
1) The screenshot you provided above is from field setting of Toolset Types plugin
2) The option "Default Value" option does not work as you mentioned above:
the field can not be blank or zero if Default Value has a value
So users can still set the field value as blank or zero, for example, if you the field value as blank, the Types shortcode [types ...] will output the result as blank.

If you want to setup a required custom field, please enable validation: Required, for example:
Create a custom single line field, you will see the validation option.

#1377739

Thanks for the reply, Luo.

Yes, the screenshot is from Toolset Types > Custom Fields. You will need some custom fields before creating a form right? So the two work together.

Sorry, your explanation of Default Value function makes no sense to me. The mouse over help tip reads: This is the initial value of the field.

Let me set an example. I have custom field named Phone Number, and as an option, I enter "N/A" in the Default Value for this field. So on the CRED form, when a user leaves the field blank (no phone number entered), I want the output template to display "N/A" as the default value instead of showing nothing. That is, Phone Number: N/A. Because Phone Number: (blank) just doesn't look good. And I don't want to make the custom field as required to be filled in by the user.

Otherwise, what is Default Value option is for, how does it work exactly, and why would anyone need it?

#1377749

I assume talking about Types shortcode [types ...], and you are going to display the custom field default value when field value is blank.

If it is, there isn't such kind of built-in feature within Toolset Types plugin. You can add a feature request for it:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
Our developers will evaluate it.

The default value works only for when you create the post, it will pre-fill the phone number field with default value "N/A", your user can clear the field value to blank.

After save post, the Types shortcode [types field='phone-number'][/types] will display the value from website database, since it is empty, it will output blank value.

In your case, you might consider to use [wpv-conditional] shortcode to check "Phone Number" field's value, if it is blank/empty, then display text "N/A", for example:

[wpv-conditional if="( $(wpcf-phone-number) eq '' )"]N/A[/wpv-conditional]
[wpv-conditional if="( $(wpcf-phone-number) eq '' )" evaluate="false"][types field='phone-number'][/types][/wpv-conditional]

More help:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/

#1377859

Ok, I see what you're saying. Default Value works only when creating a new post in WP admin, but not on the CRED form (frontend form for users to fill out.)

The conditional display shortcode as a workaround is workable. Though I have a problem using this method. My problem is that I needed to create a custom field for WP user profile, therefore, this field is considered user meta, not Types custom fields - that's the way it seems to me. So under the template editor screen when I click on Conditional Display to generate the code, all user meta fields are not available. That is, I can't use conditional display for user meta fields. Right?

Thank you.

#1378535

Yes, the Conditional Display GUI won't work for custom user field, you will need to use the shortcode directly, see our document:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/#checking-types-plugin-shortcodes

For example, below thread with current logged-in user's field value:
https://toolset.com/forums/topic/cred-conditional-codes2/

#1379581

Alright, now at least I know the Default Value function doesn't work as I fist imagined. Thanks for the help. I'll try follow the work around solution you pointed out with documentation.

Thank you.

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