Home › Toolset Professional Support › [Resolved] WP_Error::getId() with Types + Cred updates
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.
Our next available supporter will start replying to tickets in about 1.95 hours from now. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | - | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 |
- | - | - | - | - | - | - |
Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)
Tagged: Toolset Forms
This topic contains 17 replies, has 2 voices.
Last updated by Pat 6 years, 10 months ago.
Assisted by: Beda.
Hello,
I just updated your plugins on a site and found an issue.
I have some Cred forms and when I fill it and validate, then I'm getting this message : Fatal error: Call to undefined method WP_Error::getId() in /homepages/1/d485145657/htdocs/afl/wp-content/plugins/types/vendor/toolset/toolset-common/toolset-forms/classes/class.form_factory.php on line 448
I have tried to suppress the code around this line 448 ( Temporary fixing validation for checkbox/radios/skype because _cakeValidation is not working for thats hidden link).
Then no error is displayed, but the Cred form is not creating any post and after validation, I am redirected to the same page + something like /?_tt=1512819261
This is a big issue for me as this site is in production and it is difficult to move backward !
Thanks for your support
Payt
I am sorry to ask, but I need to know where from do you have that Issue Tracker Link?
This is an internal OnTheGoSystems issue tracker, that was deprecated years ago.
We use YouTrack meanwhile, but still, we never share such URL's in public, as they are for our internal purpose.
I cannot read the shared thread, as it's not existing anymore.
I suspect I know what you mean with the Skype validation thou, there are some old and known issues in Skype Fields.
Basically it needs a full refactor and debugging, which is in progress.
Now, I do not get that error you mention, when I add a Skype field to a CRED form and submit it.
Can you share with me the exact steps you take to replicate the issue?
I read that you use validation, eventually you use Custom validating?
Please can you elaborate on the exact steps so I can vastly debug it, and report it for a fast solution?
Thank you for your cooperation!
Hi Beda,
Thanks for getting back early on this.
In fact, I have updated Toolset plugins on a site (after more than 1 year of no plugins update !).
This issue is displayed only when you are using Cred. For standard display on the site, everything looks fine (meaning, Types, Views and Layout are OK?).
The issue with Cred was the one explained before, that means as soon as you try to create a new postype (and you press the submit button), then you get the mentioned error.
I had a look on the file that is reported to be the rootcause of this error (class.form_factory.php ) and there is a specific code aroubnd line 448 :
/**
* Temporary fixing validation for checkbox/radios/skype because _cakeValidation is not working for thats
* hidden link
*/
if ( !Toolset_Utils::is_real_admin() ) {
//I receive wpcf-id and wpcf[id] for the same type
if ( $field->getId() == $field->getName() &&
($field->getType() == 'checkbox' ||
$field->getType() == 'radios' ||
$field->getType() == 'skype' )
) {
//hidden link
//added sanitize_text_field for sucuri warning php.backdoor.eval_POST.010
$field_value = isset( $_POST[$field->getName()] ) ? sanitize_text_field( $_POST[$field->getName()] ) : "";
if ( $field->getType() == 'skype' ) {
$field_value = isset( $_POST[$field->getName()]['skypename'] ) ? sanitize_text_field( $_POST[$field->getName()]['skypename'] ) : "";
}
//##########################################################################################
$_tmp = $field->getValidationData();
if ( isset( $_tmp['required'] ) &&
!isset( $field_value ) ) {
$mess = $field->getTitle() . ' Field is required';
return new WP_Error( 'wptoolset_forms', $mess, array($field->getTitle() . ' Field is required') );
}
}
}
I have deleted this code to make a test.
Then, the Cred is no more displaying an error when you create a new postype, but no post is created (I hace placed a redirection on the Cred when submitted, but this is not working and after submitting the form, the same page (the one where the Cred is) is reloaded and I have this parameter in addition of the page url :/?_tt=1512819261
I can give you access to the site as it is currently in maintenance mode. Let me know if this is OK for you and open the private tab for my next reply.
Regards
Pat
I unterstand.
I tested this locally, with a Skype Field.
I used a validated (in Types) and an invalidated one.
No error appears.
Please can you provide me the previously requested details?
- Can you share with me the exact steps you take to replicate the issue?
- I read that you use validation, eventually you use Custom validating?
The ??_tt you get is only happening when you do not redirect but have you keep display the form in place.
If you redirect you get an URL parameter as ?cred_referrer_form_id
Please can you elaborate on the Field's Setup, the Form, and the validation?
You may also send me a copy of your site, using Duplicator:
https://toolset.com/faq/provide-supporters-copy-site/
Ok.
1. Please do not use Views like that. It is not intended to be used as a DataProvider.
I am aware that the snippet to clean the Views Output is provided in this forum, but it is also clear that we assume no responsibility if used.
If you had a Supporter providing you this snippet without any warning or instruction please report the thread to me.
2. I suggest to remove the generic fields to see if they are the issue (the ones that use a View as a data source)
3. I see no Skype fields in your code anywhere, but your report concerns only Skype fields.
How is it related?
Did you include a Skype Field somewhere?
I do not see it.
I need a copy of this site, online I will not be able to debug this.
If Duplicator does not work, you can either ask the Server Admin to allow it, or, you can send me:
- a database dump
- the zipped up FTP install without uploads, cache and other unneeded content.
I activated another private reply.
Hi Beda,
Seems you are right. I checked a Cred on the same site which does not contain any Views and it's working. So, now the question is : how can I do the same function without using a nested Views (meaning, propose the list of a specific postype that has been created by the user displaying the page)?
PS : concerning the skype, I never used this kind of field. I was just referring to the code that was in error (line 448 of the class.form_factory.php file !).
Regards
Pat
Hi Beda,
Some additional info :
It seems that as soon as a generic field is used (even if no Views in the options), then, I'm getting the error message :
Fatal error: Call to undefined method WP_Error::getId() in /homepages/1/d485145657/htdocs/afl/wp-content/plugins/types/vendor/toolset/toolset-common/toolset-forms/classes/class.form_factory.php on line 448
If I suppress all generic fields, then everything works fine !
Regards
Pat
Hi Beda,
Another point : you told me nested Views was not supported in Toolset, but when you create a custom field (using the Toolset editor inside Cred), then you can define a shortcode that will be used as options?
Can you tell me what is the meaning of this?
Perhaps the rootcause is the generic field itself and not the nested Views?
Regards
Pat
So, now the question is : how can I do the same function without using a nested Views (meaning, propose the list of a specific postype that has been created by the user displaying the page)
I think this here should help:
https://toolset.com/forums/topic/i-want-to-only-display-the-parent-items-of-the-current-user-in-a-select-box-2/
PS : concerning the skype, I never used this kind of field. I was just referring to the code that was in error (line 448 of the class.form_factory.php file !).
I understand. The code is related to Skype Field, I thought you have such a field in the form.
It seems that as soon as a generic field is used (even if no Views in the options), then, I'm getting the error message :
Fatal error: Call to undefined method WP_Error::getId() in /homepages/1/d485145657/htdocs/afl/wp-content/plugins/types/vendor/toolset/toolset-common/toolset-forms/classes/class.form_factory.php on line 448
If I suppress all generic fields, then everything works fine !
I tested this as well with generic fields, at no avail, I see no errors.
Can you send me the data so I can duplicate the site?
Eventually this is a compatibility issue or some very specific setting that I miss!
Thank you
Sorry, our latest posts crossed each other.
Another point : you told me nested Views was not supported in Toolset, but when you create a custom field (using the Toolset editor inside Cred), then you can define a shortcode that will be used as options?
Can you tell me what is the meaning of this?
Perhaps the rootcause is the generic field itself and not the nested Views?
Yes, you may use ShortCodes there, but not Views ShortCodes.
It should be a Custom ShortCode that returns exactly what you expect in JSON format.
PS:
Private reply active so to submit the missing data if possible.
Hi Beda,
Thanks for sharing.
What about my specific case where I have 3 different Cred generic fields. 2 need to get the postypes of the current logged user and the third needs the page id where the Cred is displayed?
Regards
Pat
I cannot replicate the issue, furthermore the issue seems to be a different than described, since as mentioned the URL parameters are not matching what we see when we create such forms
Please send me a Database Snapshot and a Zipped Install of WordPress, or, eventually, the CRED form export with all fields - but that might result in a not replicable issue as well, since often it depends a lot on specific settings that might even be from other plugins.
Can you submit me this data, so I can find a solution ASAP for you?
Thank you!
Hi Beda,
Have you been able to retrieve the site I have sent to you via wetransfer link?
Let me know
Regards
Pat
Hi Beda,
In the meantime, I have tried to use your proposal. Here what I did (taking into account I have 2 generic fields to manage in the same Cred) :
In the function.php file :
// Selection des post chevaux concours du user connecté dans CRED
function get_parents_chev ($atts) {
global $current_user;
get_currentuserinfo();
$author_query = array('post_type' => 'chevaux-concours', 'posts_per_page' => '-1','author' => $current_user->ID,);
$author_posts = new WP_Query($author_query);
$parent_chev_ids = "";
while($author_posts->have_posts()) : $author_posts->the_post();
$parent_chev_ids .= get_the_ID() .",";
endwhile;
return $parent_chev_ids;
}
add_shortcode('get-parents-chev', 'get_parents_chev');
// Selection des post cavaliers concours du user connecté dans CRED
function get_parents_cava($atts) {
global $current_user;
get_currentuserinfo();
$author_query = array('post_type' => 'cavaliers-concours', 'posts_per_page' => '-1','author' => $current_user->ID,);
$author_posts = new WP_Query($author_query);
$parent_cava_ids = "";
while($author_posts->have_posts()) : $author_posts->the_post();
$parent_cava_ids .= get_the_ID() .",";
endwhile;
return $parent_cava_ids;
}
add_shortcode('get-parents-cava', 'get_parents_cava');
In the JS of the Cred form :
jQuery('document').ready(function(){
var post_parents = jQuery('#parents_id').val()
var arr = post_parents.split(',');
jQuery("[name=_wpcf_belongs_chevaux-concours_id] > option").each(function() { //change "page" to your parent post slug
var option_val = jQuery(this).val();
if( jQuery.inArray(option_val, arr) == -1 && option_val != -1 ){
jQuery(this).remove();
}
});
});
jQuery('document').ready(function(){
var post_parents = jQuery('#parents_id').val();
var arr = post_parents.split(',');
jQuery("[name=_wpcf_belongs_cavaliers-concours_id] > option").each(function() { //change "page" to your parent post slug
var option_val = jQuery(this).val();
And in the Cred form :
[credform class="cred-form cred-keep-original"]
<div class="cred-label">Choix du cheval :</div>
This is only for test display: [get-parents-chev]
[cred_field field='_wpcf_belongs_chevaux-concours_id' type='select']
</div>
<div class="bloc">
<div class="cred-label">Choix du cavalier :</div>
This is only for test display: [get-parents-cava]
[cred_field field='_wpcf_belongs_cavaliers-concours_id' value='' order='date' ordering='desc' select_text='--- not set ---' class='form-control' output='bootstrap']
</div>
[cred_field field="form_submit" value="Commander" urlparam=""]
[/credform]
If I look at the result of the shortcodes [get-parents-chev] and [get-parents-cava], that's OK, but in the Cred form, I have a selection box that appears and ask to place 2 caracters to find the posts. Then, as soon as 2 caracters are entered, all posts are listed (not only those from the current user !).
Did I miss something?
Regards
Pat
New threads created by Beda and linked to this one are listed below:
Hi Beda,
I have tried to implement only the code you proposed in the https://toolset.com/forums/topic/i-want-to-only-display-the-parent-items-of-the-current-user-in-a-select-box-2/
First, it seems something is missing in the html part as we do not have any reference to #parents_id (which is used in the JS part). So I added the <input>.
Here is what I have placed :
[credform class="cred-form cred-keep-original"]
<label class="cred-label">
Choose Parent
</label></br>
This is only for test display: [get-parents]</br></br>
</br><input type="hidden" id="parents_id" value="[get_parents]" />
[cred_field field='_wpcf_belongs_chevaux-concours_id' value='']
[cred_field field="form_submit" value="Commander" urlparam=""]
[/credform]
And for the JS :
jQuery('document').ready(function(){
var post_parents = jQuery('#parents_id').val();
var arr = post_parents.split(',');
jQuery("[name=_wpcf_belongs_chevaux-concours_id] > option").each(function() { //change "page" to your parent post slug
var option_val = jQuery(this).val();
if( jQuery.inArray(option_val, arr) == -1 && option_val != -1 ){
jQuery(this).remove();
}
});
});
Last for the function.php :
function get_parents($atts) {
global $current_user;
get_currentuserinfo();
$author_query = array('post_type' => 'chevaux-concours', 'posts_per_page' => '-1','author' => $current_user->ID,);
$author_posts = new WP_Query($author_query);
$parent_ids = "";
while($author_posts->have_posts()) : $author_posts->the_post();
$parent_ids .= get_the_ID() .",";
endwhile;
return $parent_ids;
}
add_shortcode('get-parents', 'get_parents');
I still have the same issue, meaning when I display the form, the shortcode is working fine (result is : 45270,43025,42810,42801,42800,42799,42795,41194,41193,41192,38148,11614,9020,9017,9014, which is the correct posts created by myself) but the select box does not display all options (only a message "define parents" with the possibility to enter some caracters). If I enter some caracters, then I can see that all parents with these caracters are listed (not only the ones I have created).
Any idea?
I think if we can solve this point, I should be able to implement the right solution on my site, so you do not have to rebuilt a complete site with the zip file I have sent thanks to wetransfer.
Regards
Pat