Skip Navigation

[Résolu] [CRED] Bug with jQuery/JSON and CRED Upload Field (created with Types)

This support ticket is created Il y a 8 années et 2 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 10:00 - - - - -
- - - - - - -

Supporter timezone: Africa/Cairo (GMT+02:00)

Marqué : 

This topic contains 17 réponses, has 3 voix.

Last updated by Mohammed Il y a 8 années et 1 mois.

Assisted by: Mohammed.

Auteur
Publications
#364495

Added an upload field with Types and it works fine in the backend (when edititing single custom post type).

I then added that field in CRED (in a Edit Content Form and in a New Content form), to use on frontend.
[cred_field field='rp-file-upload' post='rate-plan' value='' urlparam='']

In both cases, on frontend page (with form) load, I get:
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
hidden link
(the line says "return window.wrappedJSObject || window;")

This happens in both cases where File Upload is only single value, or multiple.

Keep in mind Im using jQuery 2.1.4.

Any advice/fix?

Thank you

#364508

I have found out that the error ONLY occurs when the file upload cred field is empty.

So if the content had some files uploaded already (from backend), there's no error at all.
And that's why I always get error on the New Content Form (it's always empty of course), and in Edit Content Form (but only when there are no uploaded files yet).

Hope this helps you fix the bug asap!

#364568

Dear Sanny,

I can not duplicate same problem in my localhost, please try this:
1) Deactivate other plugins and switch to wordpress default theme, and test again
2) Enable PHP debug mode, copy and paste the debug logs here
PHP Debugging
In case you think that Types or Views are doing something wrong (what we call a bug), you should enable PHP error logging. Again, edit your wp-config.php file and add the following:

ini_set('log_errors',TRUE);
ini_set('error_reporting', E_ALL);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
This will produce a file called ‘error_log.txt’ in your WordPress root directory. Make sure that the web server can create and write this file. If it cannot, use an FTP program to create the file and make it writable to Apache (normally, user www-data).
https://toolset.com/documentation/user-guides/debugging-types-and-views/

#364676

I have tested with default template and no plugins (other than types, cred and views).
Error only shows when the scenario is the one described above, and with that jquery version.

#364924

Sorry, I still can not duplicate same problem in my localhost a fresh wordpress installation (4.4.2), I use below PHP codes to enqueue jQuery 2.1.4 in wordpress front-end:

if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
   wp_deregister_script('jquery');
   wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js", false, null);
   wp_enqueue_script('jquery');
}

Create a custom file field with Types plugin, and put it into a CRED form for editing post, but there isn't similar problem as you mentioned above.

Could you describe detail steps to duplicate same problem? how do you enqueue jQuery 2.1.4 in your website?

#365376

I enqueue it like you, in the parent theme.
Please activate the private response so I can give you more details.

#365547

OK, please duplicate same problem in a test site, and fill below private detail box with login details and ftp access, also point out the problem page URL and CRED form URL, I need a live website to test and debug it. thanks

#366434

Thanks for the details, I can log into your website and I did not modify anything in your website, I tested the problem page:
hidden link
But can not find the JS error:
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

Instead, I see below JS error in my chrome browser:
your-domain-name/:1 Uncaught SyntaxError: Unexpected token u
Which is referring to the first line of HTML source code:

<!doctype html>

Could you describe detail steps to duplicate same problem?

And since the latest version of wordpress 4.4.2 is using Jquery version 1.11.3, it is not recommended to use Jquery version 2.1.4

#366524

If you check on Google.....
http://stackoverflow.com/questions/25743994/syntaxerror-json-parse-unexpected-character-at-line-1-column-1-of-the-json-dat
"In chrome it resulted in 'Uncaught SyntaxError: Unexpected end of input', but Firebug showed it as 'JSON.parse: unexpected end of data at line 1 column 1 of the JSON data'."

It's "the same" error, just reported differently depending on the browser.
I also tried with the default theme (with jquery 1.11.3) and I still got that problem.

Please could you provide some help??

#366833

Sorry for the delay answer, I tried these:
1) Enqueue the jQuery 2.1.4 as I mentioned above:
https://toolset.com/forums/topic/cred-bug-with-jqueryjson-and-cred-upload-field-created-with-types/#post-364924
2) Export the Types settings and CRED form setting from your website,
3) Import them into my localhost, but still can not duplicate same problem

Since it does exist in your own website, so I escalated this thread to our 2nd Tier, hope there is any workaround for you.

#366943

I know, it's confusing. Even de-activating all plugins and with default template, we get this error.

Thank you, will wait for support.

#367800

Hello Sanny,

I’m Mohammed Toolset support second tier and I have been escalated to this thread. I’ll give my best to help you to achieve your needs through Toolset components.

This issue is not reproducible in a fresh installation. So, it may be a server confuguration issue or something specific to your installation.

I will need to replicate your website on my local machine so that I could check the issue.
For this, you'll need to temporarily install a plugin called "Duplicator" on your site. This will allow you to create a copy of your site and your content. You can provide me with the snapshot following these directions:
If you already know how Duplicator works ( http://wordpress.org/plugins/duplicator/ ), please skip the following steps and just send me the installer file and the zipped package you downloaded.

:: Duplicator instructions
. From WordPress plugin page, look for "Duplicator" and install it
. Once installed, you get a new main menu "Duplicator"
. Chose "Packages"
. Click on the first button you find in the toolbar on the right ("Create Package")
. Give it a name or leave it as is
**You can ignore the uploads directory, cache, and the archives
. Click on "Create Package Set"
. Wait until the package is ready
. Click on "Installer", then on "Package": the first one is just a PHP script, the second one is a zip file containing everything you need
. Send me both files (you probably want to use DropBox, Google Drive, or similar services, as the snapshot file will be quite big, you can also exclude the images if the file is very big )
IMPORTANT: remember to create or keep an admin account for me before creating the snapshot, or I won't be able to log-in. You may delete the new admin account once the snapshot has been built.

I will set the next reply as a private reply so you will able to provide a link to download the duplicator package.

Thanks and Best Regards

#368798
validation.png

Hi Sanny,

Thank you for your patience.

It seems that there is an issue in CRED with the field of type "file" validation.

I got rid of this error by enabling the validation on the file (please check the attached screenshot).

I also reported the issue to the development team so that they can investigate more in the issue.

Thanks.

#369260

Ok thank you for verifying the bug.
We dont want the upload field (rp-file-upload) to be required though, so we will have to hide it from the form until the bug is resolved.
Or, can you provide a temporary js fix for this?

Can you estimate when this bug will be fixed? and/or when an update to CRED will be released? for development schedule reasons, I need some ETA 🙂

#369263

Hi Sanny,

To be honest, I can't estimate the ETA for this issue but the development team is working on the issue and of course, they will provide a solution for it.

I may provide you a workaround that may solve the issue.
Please open this file, \wp-content\plugins\cred-frontend-editor\embedded\toolset\toolset-common\toolset-forms\js\jquery_upload\file_upload.js

Replace line number 38

var validation = jQuery(curr_file).attr('data-wpt-validate'); 

With this line

var validation = (jQuery(curr_file).attr('data-wpt-validate'))?jQuery(curr_file).attr('data-wpt-validate'):'[]';

And test the issue.

If you don't prefer this solution, please keep following up with this thread and I will inform you with the updates.

Thanks.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.