Home › Toolset Professional Support › [Resolved] Cred Conditional is Showing Undefined Index Error for it's Autogenerated Index
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 |
---|---|---|---|---|---|---|
- | 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 22 replies, has 3 voices.
Last updated by Dave 1 year, 11 months ago.
Assisted by: Minesh.
I am trying to:
Use Cred Conditionals to show or hide various information depending on parameters present in the URL.
I expected to see:
The form is working correctly, but 6 PHP errors are being displayed.
Instead, I got:
The following PHP errors are given, all of which are Toolset files and it originates from whatever the index of the first Cred Conditional is on the form is. These errors are in order and the full trace can be provided if requested:
E_NOTICE Undefined index: 4056_condition_1d80affb1c73b054617d8f32665b6d4a - /home/customer/www/manage.gymbubbas.co.uk/public_html/wp-content/plugins/types/vendor/toolset/toolset-common/toolset-forms/classes/class.conditional.php:263 E_WARNING array_map(): Expected parameter 2 to be an array, null given - /home/customer/www/manage.gymbubbas.co.uk/public_html/wp-content/plugins/types/vendor/toolset/toolset-common/toolset-forms/classes/class.conditional.php:325 E_WARNING array_unique() expects parameter 1 to be array, null given - /home/customer/www/manage.gymbubbas.co.uk/public_html/wp-content/plugins/types/vendor/toolset/toolset-common/toolset-forms/classes/class.conditional.php:326 E_WARNING array_intersect_key(): Expected parameter 1 to be an array, null given - /home/customer/www/manage.gymbubbas.co.uk/public_html/wp-content/plugins/types/vendor/toolset/toolset-common/toolset-forms/classes/class.conditional.php:327 E_NOTICE Undefined variable: field - /home/customer/www/manage.gymbubbas.co.uk/public_html/wp-content/plugins/types/vendor/toolset/toolset-common/toolset-forms/classes/class.conditional.php:264 E_WARNING array_unique() expects parameter 1 to be array, null given - /home/customer/www/manage.gymbubbas.co.uk/public_html/wp-content/plugins/types/vendor/toolset/toolset-common/toolset-forms/classes/class.conditional.php:264
Here is the rendered HTML of the form section containing the apparently undefined condition index:
<div class="text-center bottom-spacer"> Are you sure you wish to refund the following order<div class="cred-group 4056_condition_1d80affb1c73b054617d8f32665b6d4a" data-effectmode="none">s</div>:<br> <strong>Order #4740</strong><div class="cred-group 4056_condition_4deec86c69248468554565d9d3f2a2d9" data-effectmode="none">,</div> <div class="cred-group 4056_condition_4deec86c69248468554565d9d3f2a2d9" data-effectmode="none"> <br><strong>Order #4751</strong><div class="cred-group 4056_condition_b606284bedca7f59b28123d7922ef270" data-effectmode="none">,</div> </div> <div class="cred-group 4056_condition_b606284bedca7f59b28123d7922ef270" data-effectmode="none"> <br><strong>Order #4753</strong><div class="cred-group 4056_condition_d6ba44154363467498de2e79ff102a0d" style="display:none;" data-effectmode="none">,</div> </div> <div class="cred-group 4056_condition_d6ba44154363467498de2e79ff102a0d" style="display:none;" data-effectmode="none"> <br><strong>Order #</strong><div class="cred-group 4056_condition_d6ba44154363467498de2e79ff102a0d" style="display:none;" data-effectmode="none">,</div> </div> <div class="cred-group 4056_condition_d6ba44154363467498de2e79ff102a0d" style="display:none;" data-effectmode="none"> <br><strong>Order #</strong><div class="cred-group 4056_condition_d6ba44154363467498de2e79ff102a0d" style="display:none;" data-effectmode="none">,</div> </div> <div class="cred-group 4056_condition_d6ba44154363467498de2e79ff102a0d" style="display:none;" data-effectmode="none"> <br><strong>Order #</strong> </div> <p class="break-row"> For the collective amount of <strong>£157.50</strong>?<br><br> Deductions will be made for any classes already attended and<br> the standard admin fee will be applied <strong>to every non-deposit<br> order</strong> as detailed below, unless waivered. </p> </div>
And here is the form code for the same section from the editor:
<div class="text-center bottom-spacer"> Are you sure you wish to refund the following order[cred_show_group if="( [wpv-search-term param='oid1'] ne '' )" mode="none"]s[/cred_show_group]:<br /> <strong>Order #[order_info id='[wpv-search-term param="oid0"]']</strong>[cred_show_group if="( [wpv-search-term param='oid1'] ne 'NULL' )" mode="none"],[/cred_show_group] [cred_show_group if="( [wpv-search-term param='oid1'] ne 'NULL' )" mode="none"] <br /><strong>Order #[order_info id='[wpv-search-term param="oid1"]']</strong>[cred_show_group if="( [wpv-search-term param='oid2'] ne 'NULL' )" mode="none"],[/cred_show_group] [/cred_show_group] [cred_show_group if="( [wpv-search-term param='oid2'] ne 'NULL' )" mode="none"] <br /><strong>Order #[order_info id='[wpv-search-term param="oid2"]']</strong>[cred_show_group if="( [wpv-search-term param='oid3'] ne 'NULL' )" mode="none"],[/cred_show_group] [/cred_show_group] [cred_show_group if="( [wpv-search-term param='oid3'] ne 'NULL' )" mode="none"] <br /><strong>Order #[order_info id='[wpv-search-term param="oid3"]']</strong>[cred_show_group if="( [wpv-search-term param='oid4'] ne 'NULL' )" mode="none"],[/cred_show_group] [/cred_show_group] [cred_show_group if="( [wpv-search-term param='oid4'] ne 'NULL' )" mode="none"] <br /><strong>Order #[order_info id='[wpv-search-term param="oid4"]']</strong>[cred_show_group if="( [wpv-search-term param='oid5'] ne 'NULL' )" mode="none"],[/cred_show_group] [/cred_show_group] [cred_show_group if="( [wpv-search-term param='oid5'] ne 'NULL' )" mode="none"] <br /><strong>Order #[order_info id='[wpv-search-term param="oid5"]']</strong> [/cred_show_group] <p class='break-row'> For the collective amount of <strong>£[wpv-search-term param="rt"]</strong>?<br /><br /> Deductions will be made for any classes already attended and<br /> the standard admin fee will be applied <strong>to every non-deposit<br /> order</strong> as detailed below, unless waivered. </p> </div>
The conditional displays on the front end all appear to be working correctly, I've tested it with various parameter combinations and it works every time that I can see. I've attached a screenshot of the rendered form and here is a sample URL parameter string that is driving it:
?oid0=4740&oid1=4751&oid2=4753&rt=157.50#refundEnrolmentModal
As it is working, this isn't a massive issue at present. But I do want to resolve these PHP issues so that it doesn't cause problems in the future, and I suspect it's a bug as it's purely being derived from automatically generated Toolset content, but I may be wrong of course. I've tried debugging it a little bit, but have not had any useful discoveries apart from if I remove the first conditional that the error is referencing, then it simply changes to reference the new first conditional instead.
Hello. Thank you for contacting the Toolset support.
I checked all the [cred_show_group] conditional statements you added and I see that you are checking against NULL. For example:
[cred_show_group if="( [wpv-search-term param='oid1'] ne 'NULL' )" mode="none"]
Do you mean that the value should not be empty in the URL param "oid1" and then you want to display the content?
Hi Minesh,
The intent is to simply check if the parameter is present in the URL. I tried using empty quotes as well as NULL, but they didn't work.
Ideally I'd be able to check if a parameter was present and if it's value equalled NULL, but using code such as:
[cred_show_group if="( [wpv-search-term param='oid1'] eq 'NULL' )" mode="none"]
Wouldn't work. Testing like I have by basically saying "does this parameter has a value" I've been able to write all the form logic I need, but it's a little bit of a work around in places.
Is the NULL check relevant do you think?
What if you use: !EMPTY(value) to check the pram value is not empty.
For example:
[cred_show_group if="( !EMPTY([wpv-search-term param='oid1']) )" mode="none"] <br /><strong>Order #[order_info id='[wpv-search-term param="oid1"]']</strong>[cred_show_group if="( [wpv-search-term param='oid2'] ne 'NULL' )" mode="none"],[/cred_show_group] [/cred_show_group] [cred_show_group if="( !EMPTY([wpv-search-term param='oid2']) )" mode="none"] <br /><strong>Order #[order_info id='[wpv-search-term param="oid2"]']</strong>[cred_show_group if="( [wpv-search-term param='oid3'] ne 'NULL' )" mode="none"],[/cred_show_group] [/cred_show_group] [cred_show_group if="( !EMPTY([wpv-search-term param='oid3']) )" mode="none"] <br /><strong>Order #[order_info id='[wpv-search-term param="oid3"]']</strong>[cred_show_group if="( [wpv-search-term param='oid4'] ne 'NULL' )" mode="none"],[/cred_show_group] [/cred_show_group] [cred_show_group if="( !EMPTY([wpv-search-term param='oid4']) )" mode="none"] <br /><strong>Order #[order_info id='[wpv-search-term param="oid4"]']</strong>[cred_show_group if="( [wpv-search-term param='oid5'] ne 'NULL' )" mode="none"],[/cred_show_group] [/cred_show_group] [cred_show_group if="( !EMPTY([wpv-search-term param='oid5']) )" mode="none"] <br /><strong>Order #[order_info id='[wpv-search-term param="oid5"]']</strong> [/cred_show_group]
More info:
- https://toolset.com/documentation/programmer-reference/forms/cred-conditional-display-engine/
-
I'm fully aware of EMPTY for use in the conditional display engine, the only reason ne '' is being used is because the logic was intended to work one way but when I ran into the issue of eq not working I adjusted it to get it functional and was worrying about refining it later.
But this isn't the issue. The logic works fine, the issue raised is regarding the PHP errors the conditionals are causing.
So to answer your question, yes EMPTY does work and will be a better check, but the use of EMPTY makes no difference to the errors being generated.
I will have to check from where those notices are coming from and why and for that I've to debug this bit deeper.
Can you please share on what page/post you added the form or how can I reach there. Do I've to login as admin or front-end user to see the form on frontend?
I'll require duplicator copy of your site.
=> https://toolset.com/faq/provide-supporters-copy-site/
I have set the next reply to private which means only you and I have access to it.
I can see you've found the form, but just for the record it's ID 4056.
Triggering it is a little tricky given the context of how it's working. So please follow this link to bypass the actions needed to get to it and load a valid form:
hidden link
So long as you don't submit the form, that link will keep working through refreshes.
Thank you for sharing where the form is added on what URL.
I'll require duplicator copy of your site. Can you please send me duplicator copy of your site.
=> https://toolset.com/faq/provide-supporters-copy-site/
I have set the next reply to private which means only you and I have access to it.
Apologies for the slow response, I've been very unwell.
I've always seen support making their own copies of sites when needed, and you already have all of the login information required to install the plugin and make a duplicator copy of the site. However if you really need me to do it for you, then I'm afraid I'm going it's going to have to wait as I'm not going to have time to deal with it now before Christmas.
Please leave the thread open and if you don't do anything before I get a chance I will send you a backup of the site next week when I am able to.
Many thanks.
Before taking duplicator copy we used to ask permission from the user. Can I install the duplicator plugin and get a duplicator copy of your site using the access details you shared?
Of course, that's no problem at all
The site runs daily backups as it is, so yes you have permission to install duplicator and take a copy.
Hi Minesh,
Just checking in to see if any progress has been made and to supply a new bit of information.
When I submit the form via AJAX, it loads the spinner and then keeps the form open, even though it is generating validation errors which I can see via code dumps. Instead, it simply prints the following to the console:
#cred_form_4056_1_1 conditional.js?ver=4.1.11:67 s.fn.init [prevObject: s.fn.init(1)] conditional.js?ver=4.1.11:67
The second line does expand into a lot of information about the form and the JS calls involved etc, but I couldn't specifically see any error information or why it's there. So I can only assume it's related to the six errors that are being generated by the conditionals.
So to get moving on this again, did you get a Duplicator copy of the site, or do you still need one from me?
Ok, I've done some more testing and it seems that the above get's printed to the console when there is a "die;" command in the validation code, or I'm guessing it doesn't like something that's happening with the validation in general, when submitted via AJAX.
I'm not sure if this is related to the original issue or not, but I've been trying to debug the validation code attached to this form as it is responsible for doing a LOT behind the scenes depending on how the validation plays out. But I've noticed that there are no fields being loaded into the hook at all.
At the start of your example code, there is the line;
//uncomment this if you want to print the field values print_r($fields);
So using (and expanding) this I've been checking what the hook is loading, and there is nothing except form data. The field data is completely blank. No fields, no field values. Nothing. Here is the output (Error is the correct name of a field on the form):
Beginning of Hook: Fields = Error Fields = Form Data = Array ( [id] => 4056 [post_type] => child [form_type] => edit ) End of Hook: Error Fields = Errors = Array ( [Error] => Test )
Is this causing the console error as it can't link the errors it's being supplied to a field, because no field data is being passed to the hook?
If so, is this linked to the original six errors? And do you have any idea why on earth no field data is being passed to the hook?
It feels like it could be linked as the conditionals could be blocking things, which would make it a Toolset problem again, if my original assertion is correct.
What validation hook you are using and where you added the validation hook. Can you please share those details and I'll check.
Yes - it would be great if you can send me duplicator copy of your site.
I have set the next reply to private which means only you and I have access to it.
You should be able to access a Duplicator copy of the website in this Google Drive folder:
hidden link
The hook call is located in the Toolset code file woocommerce_refund_functions, and is the first function in there called refund_validation starting on line 6. The other functions it references are all within that same file, but please ignore the state of the code at the moment, there's a lot of commented outputs and debugging attempts in there, and the actual refund function is deliberately commented out so that it won't run and I need to reset the orders each time I test it.
That should give you what you need, but any problems or further questions please just ask and I'll sort you out.