Skip Navigation

[Resolved] wpv-conditional always thinks field value is empty

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

Problem: I am trying to write a conditional that tests whether a User profile custom field is empty, but the conditional doesn't seem to be working as expected.

Solution: Instead of using the $(slug) syntax, use the types usermeta field shortcode in your conditional.

[wpv-conditional if="('[types usermeta="1-1-hard-labor-symptom" output="raw"][/types]' ne '')"]The field has a value compared to a null string[/wpv-conditional]

Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/functions/
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This support ticket is created 5 years, 2 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by GamX 5 years, 2 months ago.

Assisted by: Christian Cox.

Author
Posts
#1187412
user entered value - still shows as null.png
initial value is null - works.png
User Field Settings.png

Hello, I'm using the wpv-conditional shortcode in two different ways at the top of a page to show text if a toolset field is empty, or show alternative text if it is not empty.

Later on the same page I have a toolset form with a field that is initially null. The user can enter text and submit, after which the field value should not be null.

However, the wpv-conditional text that is shown is always reflecting that the field of interest is empty, even when it is not.

Note that I have a separate wpv-conditional shortcode inside the User Form code below, but this works as expected and is not part of the issue.

Thanks for any help!

SHORTCODES USED IN POST
[wpv-conditional if="( empty($(wpcf-1-1-hard-labor-symptom)) )"]
This field is empty or does not exist[/wpv-conditional]

[wpv-conditional if="( NOT(empty($(wpcf-1-1-hard-labor-symptom))) )"]This field is not empty[/wpv-conditional]

[wpv-conditional if="( $(wpcf-1-1-hard-labor-symptom) eq '' )"]
The field is empty when comparing to null string[/wpv-conditional]

[wpv-conditional if="( $(wpcf-1-1-hard-labor-symptom) ne '' )"]
The field has a value compared to a null string[/wpv-conditional]

[cred_user_form form='1-1-map-form-1']

TOOLSELT USER FORM
[creduserform]
<div class="form-group">
<label>[types usermeta='1-1-magical-first-name' current_user='true'][/types], all day you have been hauling large stones over a long distance. What is one way this hard labor affects your physical body?</label>
[cred_field field="1-1-hard-labor-symptom" force_type="field" class="form-control" output="bootstrap"]
</div>
[cred_field field="form_submit" output="bootstrap" value="Activate" class="btn btn-primary btn-lg"]
[/creduserform]
[wpv-conditional if="('[wpv-search-term param="_success"]' NE '')"]
Success! Your answer has been activated.
<p></p>
[/wpv-conditional]

#1187712

p.s. In the 3rd and forth wpv-conditional statements above, the cut and paste makes it look like I'm using one double-quote after eq and after ne... but they are actually 2 single quotes in each instance.

#1187753

Hi, I assume you're talking about this Form, correct?
hidden link

If so, where can I see it on the front-end of your site? It's not immediately obvious to me based on your description so far. Also, you should select at least one role to edit in this Form. Right now, no roles are selected. Other than that, I don't see anything obviously wrong here.

#1187755
Screen Shot 2019-01-20 at 2.34.02 PM.png

Hi Christian, yes that's the correct form.

It probably doesn't look like a normal form as I'm using it differently than most, but here is the form shortcode:
[cred_user_form form='1-1-map-form-1']

And that shortcode is at the bottom of the following post:
hidden link

I'm attaching an image of the page. The form has a single field and the label is actually a question that begins with "Ophiar" and is followed by a field where I entered the word "stronger." The Activate button is really a Toolset Submit button

I also updated the form so that all roles are checked, but the problem still persists. The two test shortcodes at the top of the attached post still indicate that the field value is blank when it is not (since I entered the word "stronger").

Thanks!

#1187781

Okay the $(wpcf-field-slug) syntax isn't going to be useful with User fields. Instead, you should use the Types usermeta field shortcode like this:

[wpv-conditional if="('[types usermeta="1-1-hard-labor-symptom" output="raw"][/types]' ne '')"]The field has a value compared to a null string[/wpv-conditional]
#1187790

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.