Home › Toolset Professional Support › [Resolved] How to check for a Custom User Field value when inputting a CPT Post Form
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)
This topic contains 25 replies, has 2 voices.
Last updated by Christian Cox 3 years, 5 months ago.
Assisted by: Christian Cox.
Tell us what you are trying to do?
Hi guys 🙂
- I have a custom post type called 'Reference'
- I have a custom user role of 'Client' (and this user role has a custom user field of 'Credits' - basically if a 'Client' has at least 1 'Credit' then they have the ability to input a 'Reference' post). A 'Client' can only input a 'Reference' post into their own account.
- I also have a parallel CPT of 'Client', which automatically gets created when the User is setup. Having this as a Post Type (as well as a User Role) allows me to then have Relationships between a 'Client' and a 'Reference' (this is all setup and all working perfectly).
- I have another custom user role of 'Staff'. The Staff Users can input a 'Reference' for ANY 'Client' (as long as that Client User has at least 1 Credit of course).
So basically, both 'Clients' and 'Staff' have the ability to input a 'Reference', however 'Clients' can only input their own Reference, whereas Staff can input a Reference for ANY Client.
- Currently, regarding the 'Client' inputting their own Reference - I this this working perfectly (via a separate support thread, thank you). I have a conditional statement that checks the 'Credit' field of the current logged in User, and if they have 1 or more Credits, then they can see the 'Reference' input post form - if they have 0 credits then they see an error message instead telling them they need to buy credits. Like I say, this is all working fine, I even have it so that after the post is entered, the 'Credit' field gets reduced by an increment of 1 🙂
- However, the issue I am having, is regarding 'Staff' inputting a Reference. I have no way (currently) of the Reference Post Input form stopping them from being allowed to input a Reference for any of the Clients.
My Reference Post Form has a field on it 'Linked Client Account' - this is a relationship field which allows me to link the Client to the Reference, and it is a 'select' field.
So Ideally, what I would like, is when I click this select field (and select my Client email address which is the post title of my 'Client' CPT post), is that the form then checks (in the background possibly, is that AJAX?) the User which matches that email address, to see if that User has a Credit, and if not, an error message shows and the 'Staff' then cannot input a Reference for that Client?
Also as a safety check I will need some sort of validation when I click the Submit button, that checks again if the User which matches the 'linked Client account' field has any Credits, and if not the form will not submit (and the same error message shows)?
I hope that all makes sense!
Thank you so much as always for your excellent support, I cannot thank you guys enough - I am slowly starting to understand how all of the things in Toolset work together (and the API etc), but so far I cannot work out how to do this myself 🙂
Is there any documentation that you are following?
No
Is there a similar example that we can see?
No
What is the link to your site?
I can provide a link, plus administrator login credentials if required, via a private box
So Ideally, what I would like, is when I click this select field (and select my Client email address which is the post title of my 'Client' CPT post), is that the form then checks (in the background possibly, is that AJAX?) the User which matches that email address, to see if that User has a Credit, and if not, an error message shows and the 'Staff' then cannot input a Reference for that Client?
It sounds like you would need some type of AJAX API to validate this information, but no such AJAX API exists for Forms. The validation API we offer is only available upon form submission, on the backend. We have documentation available for this API here:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
You can click the orange "More" button to see a couple of examples showing how to test the values of specific fields in the Form. You'll need to check the value of the select field you mentioned, then use that to query Users somehow to get the specific Client User profile. Then you can use get_user_meta or the Types field API to check the User's credits count, and return an error if no credits are available.
Let me know if you run into trouble and I can provide example code if necessary.
Hi Christian I hope you're well.
Thanks very much for the suggestion - I'm just working on this using the cred_form_validate mthod suggested - I think I can get it to work but I will report back in a few days, just wanted to update you 🙂
Speak soon,
Keith
No problem, I stand by for your update.
Hi Christian,
I've tried and tried to work out what to do, but I just can't get it to work and I'm at the point of giving up now. So I'm sorry but I really need your help 🙁 I just can't get my head around what to do...
I understand fully that the AJAX option I was originally looking for is not possible - so just being able to have something which runs when the Staff User clicks to submit the post form will be fine.
I need a way to do the following:
- Currently I have a relationship field loading in the Clients email, this is the form field code:
[cred_field field='@client-reference.parent' class='form-control' output='bootstrap' select_text='--- not set ---' required='true']
So my slug is 'client-reference', and this loads in an email address.
- When 'cred_form_validate' runs, I need some code which will take that email address in the 'client-reference' field, and then check the 'User' which has that email address.
That User has a Custom User Field called 'ORC Credits' (the slug is 'orc-credits' so I'm guessing that would mean it looks for 'wpcf-orc-credits'? See I try my best to understand haha), so I need to be able to check that the user with that email address has at least 1 ORC Credit, then if so it will save the post (and then reduce the ORC Credits field for that user by an increment of 1) - but if they do NOT have any ORC Credits then I need for the post to NOT submit and for an error message to say something like "This Client does not have any ORC Credits and therefore cannot post any References at this time"..
Like I say I really have tried to work this out, but I've been staring at it for hours now and I just cannot figure out how to do it. If you can help me I would be extremely grateful.
I only wish that you guys offered training courses as I'm sure I could get a really good understanding of how it all worked if there were more videos or like I say a 1 day live training course - I would happily pay whatever the cost! Then I wouldn't have to keep begging for bits of code haha. Anyway not to worry, if you could help me with some code examples here that would be amazing.
Thanks again,
Keith
Okay I have some example code available. The field value of a reference field will be the reference post ID, but you need the title because that's where the email address is found if I understand correctly. Then you can use that to query Users by email, get the User ID, and then call get_user_meta to fetch the User's custom field value. Here's an example:
// Reference: https://toolset.com/forums/topic/how-to-check-for-a-custom-user-field-value-when-inputting-a-cpt-post-form/ add_filter('cred_form_validate','tssupp_form_validation', 10, 2); function tssupp_form_validation( $field_data, $form_data ) { $forms = array( 123 ); $user_field_slug = 'user-field-slug'; $reference_slug = 'reference-slug'; $error_message = 'No remaining credits'; // field data are field values and errors list($fields,$errors)=$field_data; // validate if correct CRED form ID if ( in_array( $form_data['id'], $forms ) ) { // get the reference post ID $ref_id = isset( $fields[$reference_slug]['value']) ? $fields[$reference_slug]['value'] : 0; if($ref_id) { // get the reference post title (email address) and use that to query Users $ref_title = get_the_title($ref_id); $user = get_user_by('email', $ref_title); // get the User credits information from User field $user_field = get_user_meta($user->ID, 'wpcf-'. $user_field_slug, true); // test the value of the user field. add an error message if no credits remain if(intval($user_field) < 1) { $errors[$reference_slug]=$error_message; } } } return array( $fields, $errors ); }
You'll need more customization I'm sure, but this is a general template you can use to get going.
Hi Christian - thank you so much for your help.
I have tried implementing your code, but unfortunately I cannot get it to work. Here is the code I am using:
add_filter('cred_form_validate','ts_ref_input_form_validation_staff', 10, 2);
function ts_ref_input_form_validation_staff( $field_data, $form_data ) {
$forms = array( 1696 );
$user_field_slug = 'orc-credits';
$reference_slug = 'reference';
$error_message = 'No remaining credits';
// field data are field values and errors
list($fields,$errors)=$field_data;
// validate if correct CRED form ID
if ( in_array( $form_data['id'], $forms ) ) {
// get the reference post ID
$ref_id = isset( $fields[$reference_slug]['value']) ? $fields[$reference_slug]['value'] : 0;
if($ref_id) {
// get the reference post title (email address) and use that to query Users
$ref_title = get_the_title($ref_id);
$user = get_user_by('email', $ref_title);
// get the User credits information from User field
$user_field = get_user_meta($user->ID, 'wpcf-'. $user_field_slug, true);
// test the value of the user field. add an error message if no credits remain
if(intval($user_field) < 1) {
$errors[$reference_slug]=$error_message;
}
}
}
return array( $fields, $errors );
}
I have a feeling that the issue is the $reference_slug - I'm not too sure what I am supposed to put in here? I have tried the following:
$reference_slug = 'reference'; ('reference' being the slug of my Reference CPT)
$reference_slug = 'client-reference'; ('client-reference' being the slug of my relationship field)
$reference_slug = '@client-reference.parent'; ('@client-reference.parent' I thought I would try this as that is the code used in my shortcode to load the field in my form)
Unfortunately in all 3 cases, this did not work. I tried inputting a reference for a user which has 0 orc-credits (and therefore it should not process the post and should give me an error message), but in all 3 cases the post got processed.
Can you advise if I have misunderstood what needs to go in the $reference_slug variable please? Or maybe something else? And of course just to point out that 1696 is the ID of my Post Form for inputting a new 'Reference' post type 🙂
Thanks a lot,
Keith
Hi Christian, sorry to hurry you, but are you available to help on this today? It's just that if you can update me with an answer then I can work on this over the weekend 🙂
Thank you very much,
Keith
Hi guys, is anyone available to give me an update on this please as I haven't heard anything in 3 days?
Many thanks,
Keith
Hello, I'm available today and looking at this now. I'll give you an update shortly.
When dealing with problems in custom code, it always helps to turn on error logging and debug each step of the problem. We can add some error log statements to find out exactly why it's not working as expected. In my local test, I was using the slug of the post reference field in the $reference_slug variable, so I suspect yours should be client-reference based on the information you shared. Please add error logging statements throughout the code as shown here:
add_filter('cred_form_validate','ts_ref_input_form_validation_staff', 10, 2); function ts_ref_input_form_validation_staff( $field_data, $form_data ) { $forms = array( 1696 ); $user_field_slug = 'orc-credits'; $reference_slug = 'client-reference'; $error_message = 'No remaining credits'; // field data are field values and errors list($fields,$errors)=$field_data; // validate if correct CRED form ID if ( in_array( $form_data['id'], $forms ) ) { error_log('validating form: ' . $form_data['id']); error_log(print_r($fields, true)); // get the reference post ID $ref_id = isset( $fields[$reference_slug]['value']) ? $fields[$reference_slug]['value'] : 0; if($ref_id) { // get the reference post title (email address) and use that to query Users $ref_title = get_the_title($ref_id); error_log('ref_title: ' . $ref_title); $user = get_user_by('email', $ref_title); // get the User credits information from User field $user_field = get_user_meta($user->ID, 'wpcf-'. $user_field_slug, true); error_log('user_field: ' . $user_field); // test the value of the user field. add an error message if no credits remain if(intval($user_field) < 1) { $errors[$reference_slug]=$error_message; } } } return array( $fields, $errors ); }
To read the error log information, you'll need to turn on error logging. If you're not familiar with error logs, I can show you how to activate one temporarily. Go in your wp-config.php file and look for
define('WP_DEBUG', false);
Change it to:
define('WP_DEBUG', true);
Then add these lines, just after the WP_DEBUG line:
define('WP_DEBUG_LOG', dirname(__FILE__) . '/error_log.txt'); define( 'WP_DEBUG_DISPLAY', false ); @ini_set( 'display_errors', 0 ); define('WP_DISABLE_FATAL_ERROR_HANDLER',true);
Test the form again. If error logging is turned on successfully and this validation script is active, it should create an error_log.txt file in your site's root directory. Use FTP to look for this file in the same directory as wp-config.php. You may need to click "Refresh" in your FTP browser to see a new file appear. Please download this file to your computer, open it in any text editing software, and copy+paste its contents in your next reply.
Hi Christian, great to hear from you - thank you so much!
Thanks for explaining regarding setting up the error debugging (I knew already about enabling WP_DEBUG but not the other stuff and that was getting very frustrating, as I don't even know a way to find out what my variables contain, whether they were empty, or just containing the wrong values etc - I was tearing my hair out!)
So I have carried out your instructions (I pasted in your updated code to my functions.php, I set WP_DEBUG to true, and I added the code underneath that line). I once again entered a reference for a 'Client' user which I know has 0 credits, and once again the post was successful when it shouldn't have been.
As you mentioned, I now have an error_log.txt file in my root folder, which is full of errors, most of them look like they are related to my template, but then there is also lots of information regarding my form 🙂
So I will paste that code into a separate message after this one, hopefully you can see from that what the issue is.
I will await your reply, thanks very much for your help I really appreciate it,
Keith
Here is the code from the error_log.txt file:
[21-Jun-2021 19:56:37 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 19:56:37 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:56:37 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:56:37 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 19:56:37 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:56:37 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:56:37 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 19:56:37 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:56:37 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:56:45 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 19:56:45 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:56:45 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:56:45 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 19:56:45 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:56:45 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:56:45 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 19:56:45 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:56:45 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:56:49 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 19:56:49 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:56:49 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:56:49 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 19:56:49 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:56:49 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:56:49 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 19:56:49 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:56:49 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:57:01 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 19:57:01 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:57:01 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:57:01 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 19:57:01 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:57:01 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:57:01 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 19:57:01 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:57:01 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:57:03 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 19:57:03 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:57:03 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:57:03 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 19:57:03 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:57:03 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:57:03 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 19:57:03 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:57:03 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:57:08 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 19:57:08 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:57:08 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:57:08 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 19:57:08 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:57:08 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:57:08 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 19:57:08 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 19:57:08 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:02:10 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 20:02:10 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:02:10 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:02:10 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 20:02:10 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:02:10 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:02:10 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 20:02:10 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:02:10 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:03:01 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 20:03:01 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:03:01 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:03:01 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 20:03:01 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:03:01 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:03:01 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 20:03:01 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:03:01 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:03:02 UTC] validating form: 1696
[21-Jun-2021 20:03:02 UTC] Array
(
[@client-reference.parent] => Array
(
[value] =>
[name] => @client-reference.parent
[type] => select
[repetitive] =>
[validation] => Array
(
[required] => Array
(
[message] => This field is required
[active] => 1
)
)
)
[organisation] => Array
(
[value] => Array
(
[0] => 3
)
[name] => organisation
[type] => taxonomyhierarchical
[repetitive] =>
)
[contract-type] => Array
(
[value] => Array
(
[0] => 4
)
[name] => contract-type
[type] => taxonomyhierarchical
[repetitive] =>
)
[post_title] => Array
(
[value] => ORC-680453-2021-06-21
[name] => post_title
[type] => textfield
[repetitive] => 0
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => 1
[message] => This field is required
)
)
)
[wpcf-contract-name] => Array
(
[value] => dbwjkl
[name] => wpcf-contract-name
[type] => textfield
[repetitive] => 0
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please enter the contract name.
)
)
)
[wpcf-contract-value] => Array
(
[value] => 250000
[name] => wpcf-contract-value
[type] => numeric
[repetitive] => 0
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please enter the contract value.
)
[number] => Array
(
[active] => 1
[message] => Please enter numeric data only (no letters or special characters can be entered here).
)
)
)
[wpcf-referee-name] => Array
(
[value] => John Smith
[name] => wpcf-referee-name
[type] => textfield
[repetitive] => 0
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please enter the referee name
)
)
)
[wpcf-referee-organisation] => Array
(
[value] => Smith and Co
[name] => wpcf-referee-organisation
[type] => textfield
[repetitive] => 0
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please enter the referee organisation name.
)
)
)
[wpcf-referee-position] => Array
(
[value] => Director
[name] => wpcf-referee-position
[type] => textfield
[repetitive] => 0
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please enter the referee position.
)
)
)
[wpcf-reference-date] => Array
(
[value] => Array
(
[display-only] => June 21, 2021
[datepicker] => 1624233600
)
[name] => wpcf-reference-date
[type] => date
[repetitive] => 0
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please select the date
)
[date] => Array
(
[active] => 1
[format] => mdy
[pattern] => check.format
[message] => Please enter a valid date.
)
)
)
[wpcf-em1] => Array
(
[value] => 1
[name] => wpcf-em1
[type] => select
[repetitive] =>
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please select an option.
)
)
)
[wpcf-em2] => Array
(
[value] => 1
[name] => wpcf-em2
[type] => select
[repetitive] =>
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please select an option.
)
)
)
[wpcf-em3] => Array
(
[value] => 1
[name] => wpcf-em3
[type] => select
[repetitive] =>
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please select an option.
)
)
)
[wpcf-em4] => Array
(
[value] => 1
[name] => wpcf-em4
[type] => select
[repetitive] =>
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please select an option.
)
)
)
[wpcf-cc5] => Array
(
[value] => 1
[name] => wpcf-cc5
[type] => select
[repetitive] =>
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please select an option.
)
)
)
[wpcf-cc6] => Array
(
[value] => 1
[name] => wpcf-cc6
[type] => select
[repetitive] =>
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please select an option.
)
)
)
[wpcf-cc7] => Array
(
[value] => 1
[name] => wpcf-cc7
[type] => select
[repetitive] =>
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please select an option.
)
)
)
[wpcf-cc8] => Array
(
[value] => 1
[name] => wpcf-cc8
[type] => select
[repetitive] =>
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please select an option.
)
)
)
[wpcf-tc9] => Array
(
[value] => 1
[name] => wpcf-tc9
[type] => select
[repetitive] =>
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please select an option.
)
)
)
[wpcf-tc10] => Array
(
[value] => 1
[name] => wpcf-tc10
[type] => select
[repetitive] =>
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please select an option.
)
)
)
[wpcf-tc11] => Array
(
[value] => 1
[name] => wpcf-tc11
[type] => select
[repetitive] =>
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please select an option.
)
)
)
[wpcf-ud12] => Array
(
[value] => 1
[name] => wpcf-ud12
[type] => select
[repetitive] =>
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please select an option.
)
)
)
[wpcf-ud13] => Array
(
[value] => 1
[name] => wpcf-ud13
[type] => select
[repetitive] =>
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please select an option.
)
)
)
[wpcf-ud14] => Array
(
[value] => 1
[name] => wpcf-ud14
[type] => select
[repetitive] =>
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please select an option.
)
)
)
[wpcf-ud15] => Array
(
[value] => 1
[name] => wpcf-ud15
[type] => select
[repetitive] =>
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please select an option.
)
)
)
[wpcf-hs16] => Array
(
[value] => 0
[name] => wpcf-hs16
[type] => select
[repetitive] =>
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please select an option.
)
)
)
[wpcf-o17] => Array
(
[value] => 1
[name] => wpcf-o17
[type] => select
[repetitive] =>
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please select an option.
)
)
)
[wpcf-o18] => Array
(
[value] => 6
[name] => wpcf-o18
[type] => select
[repetitive] =>
[plugin_type] => types
[validation] => Array
(
[required] => Array
(
[active] => 1
[value] => true
[message] => This field is required. Please select your rating.
)
)
)
[wpcf-o19] => Array
(
[value] =>
[name] => wpcf-o19
[type] => wysiwyg
[repetitive] =>
[plugin_type] => types
)
[form_submit_1] => Array
(
[value] => Submit Reference
[name] => form_submit_1
[type] => submit
[repetitive] =>
)
[_cred_cred_wpnonce_cred_form_1696] => Array
(
[value] => 2bf88dc426
[name] => _cred_cred_wpnonce_cred_form_1696
[type] => hidden
[repetitive] =>
)
[_cred_cred_prefix_post_id] => Array
(
[value] => 1726
[name] => _cred_cred_prefix_post_id
[type] => hidden
[repetitive] =>
)
[_cred_cred_prefix_cred_container_id] => Array
(
[value] => 39
[name] => _cred_cred_prefix_cred_container_id
[type] => hidden
[repetitive] =>
)
[_cred_cred_prefix_form_id] => Array
(
[value] => 1696
[name] => _cred_cred_prefix_form_id
[type] => hidden
[repetitive] =>
)
[_cred_cred_prefix_form_count] => Array
(
[value] => 1
[name] => _cred_cred_prefix_form_count
[type] => hidden
[repetitive] =>
)
)
[21-Jun-2021 20:03:02 UTC] PHP Notice: Trying to get property 'ID' of non-object in /var/web/site/public_html/wp-content/themes/yootheme-orc/functions.php on line 494
[21-Jun-2021 20:03:03 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 20:03:03 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:03:03 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:03:03 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 20:03:03 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:03:03 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:03:03 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 20:03:03 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:03:03 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:03:10 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 20:03:10 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:03:10 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:03:10 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 20:03:10 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:03:10 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:03:10 UTC] PHP Notice: Undefined index: showtitle in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 31
[21-Jun-2021 20:03:10 UTC] PHP Notice: Undefined variable: widget in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
[21-Jun-2021 20:03:10 UTC] PHP Notice: Trying to get property 'content' of non-object in /var/web/site/public_html/wp-content/themes/yootheme/vendor/yootheme/builder-wordpress/elements/module/templates/template.php on line 43
I just thought I would add - that looking at that error log file - it would seem to suggest that the field is empty (which would certainly explain why it is not working), I am referring to this bit:
[21-Jun-2021 20:03:02 UTC] validating form: 1696
[21-Jun-2021 20:03:02 UTC] Array
(
[@client-reference.parent] => Array
(
[value] =>
[name] => @client-reference.parent
[type] => select
[repetitive] =>
[validation] => Array
(
[required] => Array
(
[message] => This field is required
[active] => 1
)
So the 'value' has nothing next to it. But I can assure you that a value is being entered. The field is a select box - I have done a screen recording of me filling out the field to show you what happens, which you can view here:
hidden link
As you will see, I am selecting the Client 'test10@akcreation.co.uk', which also is a User which I know has 0 'ORC Credits'.
Also, it must be working, as after I submit the form, I can see that the 'Reference' post is there and it is showing 'test10@akcreation.co.uk' as the author.
Maybe that is not the issue at all but I thought it would at least be worth pointing that out to you 🙂
Thanks,
Keith
Okay thank you, it seems that the relationship field has no value here. I was under the impression this was a post reference field, but I believe in your case it is a post relationship field instead. In this case we may need to implement a workaround to get the field value from $_POST. In the current code, please find this line:
error_log(print_r($fields, true));
Just after that line, create a new line and add this code:
error_log('post relationship field value: ' . $_POST['@client-reference_parent']);
Then please test one more time and provide the updated log information. You can ignore the PHP Notices, those seem to be unrelated here.