Skip Navigation

[Resolved] view is throwing a new error about array_map

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

Problem:

Conditional display contents on the related posts custom field value in post forms.

Solution:

You can use [wpv-conditional] ... [/wpv-conditional] shortcode in form contents.

Relevant Documentation:

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-conditional

This support ticket is created 2 years, 4 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
- 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 8 replies, has 2 voices.

Last updated by eliseD-2 2 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#2242915

A view that I've been using for years is suddenly throwing this error:

Warning: array_map(): Expected parameter 2 to be an array, null given in /home/writiol6/public_html/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/toolset-forms/classes/class.conditional.php on line 325

I don't even know where to start to figure this out.

Help!

This is the page where it is happening:
hidden link

#2242923

Unfortunately, you need to be a logged-in student to view the page where the error is happening.

But this is the view that is being called on that page:

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-if url="wpcf-answer1" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer1) eq '[types field='question1rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

[wpv-if url="wpcf-answer2" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer2) eq '[types field='question2rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

[wpv-if url="wpcf-answer3" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer3) eq '[types field='question3rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

[wpv-if url="wpcf-answer4" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer4) eq '[types field='question4rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

[wpv-if url="wpcf-answer5" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer5) eq '[types field='question5rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

[wpv-if url="wpcf-answer6" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer6) eq '[types field='question6rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

[wpv-if url="wpcf-answer7" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer7) eq '[types field='question7rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

[wpv-if url="wpcf-answer8" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer8) eq '[types field='question8rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

[wpv-if url="wpcf-answer9" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer9) eq '[types field='question9rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

[wpv-if url="wpcf-answer10" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer10) eq '[types field='question10rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional]
[/wpv-if]

[wpv-if url="wpcf-answer11" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer11) eq '[types field='question11rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional]
[/wpv-if]

[wpv-if url="wpcf-answer12" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer12) eq '[types field='question12rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

[wpv-if url="wpcf-answer13" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer13) eq '[types field='question13rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

[wpv-if url="wpcf-answer14" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer14) eq '[types field='question14rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

[wpv-if url="wpcf-answer15" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer15) eq '[types field='question15rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

[wpv-if url="wpcf-answer16" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer16) eq '[types field='question16rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

[wpv-if url="wpcf-answer17" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer17) eq '[types field='question17rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

[wpv-if url="wpcf-answer18" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer18) eq '[types field='question18rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

[wpv-if url="wpcf-answer19" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer19) eq '[types field='question19rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

[wpv-if url="wpcf-answer20" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer20) eq '[types field='question20rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional]
[/wpv-if]

[wpv-if url="wpcf-answer21" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer21) eq '[types field='question21rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional]
[/wpv-if]

[wpv-if url="wpcf-answer22" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer22) eq '[types field='question22rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

[wpv-if url="wpcf-answer23" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer23) eq '[types field='question23rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

[wpv-if url="wpcf-answer24" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer24) eq '[types field='question24rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

[wpv-if url="wpcf-answer25" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer25) eq '[types field='question25rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

<td align="center" valign="top" style="border:2px solid #000000">[wpv-post-date format='m/d/y']</td>
<td align="center" valign="top" style="border:2px solid #000000">[show-total] / [types field='total' id='$test' format='FIELD_VALUE'][/types]</td>
<td align="center" valign="top" style="border:2px solid #000000">[types field='pass' id='$test' format='FIELD_VALUE'][/types]</td>
<td align="left" valign="top" style="border:2px solid #000000">  <u><b>[cred_link_form form='285' form_name='Answer Edit Form' text='Take Test' target='_self']</u></b></td>

</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"] <td align="left" valign="top" style="border:2px solid #000000"> </td>
<td align="center" valign="top" style="border:2px solid #000000"><font color="red"><b>0 / [types field='total' id='$test' format='FIELD_VALUE'][/types]</b></font></td>
<td align="center" valign="top" style="border:2px solid #000000">[types field='pass' id='$test' format='FIELD_VALUE'][/types]</td>
<td align="left" valign="top" style="border:2px solid #000000">  <u><b>[cred_child_link_form form='259' parent_id='-1' text='Take Test' target='_self']</b></u></td>
[/wpml-string]

[/wpv-no-items-found]
[wpv-layout-end]

#2243237

Hello,

You are using nested shortcodes:

[wpv-if...]
[wpv-conditional ...]
...
[/wpv-conditional]
[/wpv-if]

And the [wpv-if] shortcode is retired, I suggest you try to use [wpv-conditional] shortocde instead of it, for example, please this one from:

[wpv-if url="wpcf-answer1" evaluate="!empty($url)"]
[wpv-conditional if="( $(wpcf-answer1) eq '[types field='question1rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional][/wpv-if]

To:

[wpv-conditional if=" (!empty($wpcf-answer1) ) AND ( $(wpcf-answer1) eq '[types field='question1rightanswer' id='$test'][/types]' )"]
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional]

More help:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-conditional

#2243855

Thanks. But I just realized that the error is actually happening on a page that is calling a cred form - and I'm not seeing the retired wpv-if on that page. Here is the code for the cred for that is throwing the errors:

[credform class='cred-form cred-keep-original']

[cred_field field='form_messages' value='']

<center><b><u><a href="hidden link">BACK TO LABS HOME PAGE</b></u></a></center>

<br><br>Read the questions below, and use the drop-down to choose the best answer for each question. When you have finished making your choices, click the SUBMIT button at the very bottom of the page to see your results.
<br><br>
[wpv-conditional if="'[types field='description' id='$test'][/types]' ne '' "]
<b>[types field='description' id='$test'][/types]</b>
<br>
[/wpv-conditional]

[wpv-conditional if="'[types field='question1text' id='$test'][/types]' ne '' "]

<table align="center" style="border:1px solid #000000" cellspacing="0" cellpadding="0" class="no-padding">
<tr>
<td colspan="1" align="left" valign="top" style="border:1px solid #000000"><b>1.  [types field="question1text" id="$test"][/types]</b>
[wpv-conditional if="( $(wpcf-answer1) = '' )"]
<br>      A. [types field='question1answera' id='$test'][/types]
<br>      B. [types field='question1answerb' id='$test'][/types]
<br>      C. [types field='question1answerc' id='$test'][/types]
<br>      D. [types field='question1answerd' id='$test'][/types]
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-answer1) != '' )"]
[wpv-conditional if="( $(wpcf-answer1) ne 'A' )"]
<br>      A. [types field='question1answera' id='$test'][/types]
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-answer1) eq 'A' )"]
[wpv-conditional if="'[types field='question1rightanswer' id='$test'][/types]' eq 'A' "]
<br>      <font color="green"><b>A. [types field='question1answera' id='$test'][/types]        Your response is correct.</b></font>
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional]
[wpv-conditional if="'[types field='question1rightanswer' id='$test'][/types]' ne 'A' "]
<br>      <font color="red"><b>A. [types field='question1answera' id='$test'][/types]        Sorry, your response is incorrect.</b></font>
[/wpv-conditional]
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-answer1) ne 'B' )"]
<br>      B. [types field='question1answerb' id='$test'][/types]
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-answer1) eq 'B' )"]
[wpv-conditional if="'[types field='question1rightanswer' id='$test'][/types]' eq 'B' "]
<br>      <font color="green"><b>B. [types field='question1answerb' id='$test'][/types]        Your response is correct.</b></font>
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional]
[wpv-conditional if="'[types field='question1rightanswer' id='$test'][/types]' ne 'B' "]
<br>      <font color="red"><b>B. [types field='question1answerb' id='$test'][/types]        Sorry, your response is incorrect.</b></font>
[/wpv-conditional]
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-answer1) ne 'C' )"]
<br>      C. [types field='question1answerc' id='$test'][/types]
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-answer1) eq 'C' )"]
[wpv-conditional if="'[types field='question1rightanswer' id='$test'][/types]' eq 'C' "]
<br>      <font color="green"><b>C. [types field='question1answerc' id='$test'][/types]        Your response is correct.</b></font>
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional]
[wpv-conditional if="'[types field='question1rightanswer' id='$test'][/types]' ne 'C' "]
<br>      <font color="red"><b>C. [types field='question1answerc' id='$test'][/types]        Sorry, your response is incorrect.</b></font>
[/wpv-conditional]
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-answer1) ne 'D' )"]
<br>      D. [types field='question1answerd' id='$test'][/types]
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-answer1) eq 'D' )"]
[wpv-conditional if="'[types field='question1rightanswer' id='$test'][/types]' eq 'D' "]
<br>      <font color="green"><b>D. [types field='question1answerd' id='$test'][/types]        Your response is correct.</b></font>
[add-to-total][types field='points' id='$test'][/types] * 1[/add-to-total]
[/wpv-conditional]
[wpv-conditional if="'[types field='question1rightanswer' id='$test'][/types]' ne 'D' "]
<br>      <font color="red"><b>D. [types field='question1answerd' id='$test'][/types]        Sorry, your response is incorrect.</b></font>
[/wpv-conditional]
[/wpv-conditional]
<br><br> <b>Explanation:</b>[types field='question1explanation' id='$test'][/types]
[/wpv-conditional]
[/wpv-conditional]
[cred_show_group if="'[types field='question1text' id='$test'][/types]' ne '' "]
<center><b>Choose/change your answer:</b><br>[cred_field field='answer1' post='answer' value='' urlparam='']</center>
[/cred_show_group]
</td></tr> </table>

<table>
<tr>
<td colspan="1" align="center" valign="top" style="border:1px solid #000000">
<center>[cred_field field='form_submit' value='Submit' urlparam='']</center>
</td></tr>
</table>

<br>
<center>
<h3><b>Your score is [show-total] out of [types field='total' id='$test' format='FIELD_VALUE'][/types].</b></h3>
<h4><b>(A passing grade is [types field='pass' id='$test' format='FIELD_VALUE'][/types].)</b></h4>

[/credform]
<br><a href="hidden link"><b><u>BACK TO LABS HOME PAGE</b></u></a></center>

#2243953

You are using quite complicated codes, please provide a copy of your website in below private message box, you can put the package files in your own google drive disk, share the link only, also point out the problem page URL and view URL, I need to test and debug it in my localhost, thanks
https://toolset.com/faq/provide-supporters-copy-site/

#2244129

Thanks for the details, I can download the files, will update here if find anything

#2244927

Please try these:
Edit the post form "Answer Edit Form":
hidden link

Replace all [cred_show_group] ... [/cred_show_group]
With:
[wpv-conditional] ... [/wpv-conditional]

And test again.

The [cred_show_group] shortcode is for triggering when user change inputs in Toolset post form, but in your case, it is checking the related posts custom field value, so you need to use [wpv-conditional] ... [/wpv-conditional] shortcode instead of [cred_show_group] ... [/cred_show_group]

I have tried it in my locahost, it works fine with your duplicator package

#2245357

Thanks so much - that seems to have worked!

(I'm not sure why it changed - the original code has been working for several years)

Anyway - thanks!!!!

#2245359

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.