Skip Navigation

[Resolved] Image upload error on post form

This support ticket is created 5 years, 3 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 8 replies, has 3 voices.

Last updated by Nigel 5 years, 3 months ago.

Assisted by: Nigel.

Author
Posts
#1310931

I am trying to: Let a custom role (vendor) upload images to a post form.

Link to a page where the issue can be seen: hidden link

I expected to see: Successful image uploads.

Instead, I got: "An error occurred in the upload. Please try again later."

MORE INFO: I have a post form "Mitzvah Vendor Directory Registration" which can only be accessed if the user is logged in. So on the link above, you have both the "New user?" user form and the "Already have a login?" user form (both made in Toolset). If they already have an account and use the "Already have a login?" user form, image uploads on the form works fine.

But if they are a new user and use the "New user?" user form, they are unable to upload media. I have tried:

- putting in the custom code for auto-logging new users upon sign up (you can see it on my functions.php file)
- putting in the custom code for allowing guest users to upload media (you can also see it on my functions.php file)

I am clueless as to what in my site is causing this error. Can you help me out?

#1310953

Hi David,

Thank you for contacting us and I'd be happy to assist.

To troubleshoot, why only specific post form is not uploading images, I'll need access to the website's admin area.

Can you please share temporary admin login details?

Note: Your next reply will be private and though no changes will be made on your website, please make a complete backup copy, before sharing the access details.

regards,
Waqar

#1312275

Hi David,

Thank you for sharing the admin access.

During testing, I noticed that the issue with the image uploading is only faced if a new user is logged in automatically after registering, through custom login code.

If a new user registers and then logs out and then logs in using the login form, the image uploading works as expected.

This suggests that the custom function that is being used on the website to automatically login user, is not working completely or some security measures/plugins on the website are not treating that authentication as adequate.

I couldn't access your theme's "functions.php" file to see that custom code, but I'll recommend to temporarily disable all extra plugins, other than Toolset and then test the registration and post creation form again.

If the issue is fixed, you can start activating the deactivated plugins one-by-one, to narrow this down to a possible conflicting one.

You're also welcome to share the code that you're using for the automatic login, on the website, so I can test it on my website too.

regards,
Waqar

#1312811

This is the code that I use to automatically log the user in after registering:

add_action( 'cred_save_data', 'tssupp_cred_autologin', 10, 2 );
 
function tssupp_cred_autologin( $post_id, $form_data ){
 
    if ( 22161 == $form_data['id'] ) { // Edit as required
 
        if ( !empty( $_POST['user_login'] ) && !empty( $_POST['user_pass'] ) ) {
 
            // get the user credentials from the $_POST object
            $user = array(
                'user_login'    =>   $_POST['user_login'],
                'user_password' =>   $_POST['user_pass'],
                'remember'      =>   true
            );
            $login = wp_signon( $user, false );
 
            if ( is_wp_error($login) ) {
                error_log( $login->get_error_message() );
            }
 
        }
    }
}

Ideally, I would prefer not to have the vendors go through the login process again (thus the auto-login code). For good measure, I also have this code on my functions.php which allows guest uploads:

add_action( 'admin_init','reset_guest_caps' , 9 );
function reset_guest_caps(){
    global $current_user, $wpcf_access;
    if(isset($_GET['formid']) && $_GET['formid']==17358&&$current_user->ID==0)
    {
        $wpcf_access->settings=array();
    }
}

I thought that it could work instead of auto-logging new users, but it doesn't either. I have tried leaving one code and just running the other, I also tried having both of them on my functions.php at the same time, to no avail.

Thank you for your help!

#1315377

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi David

Waqar has holidays this week, so let me jump in here.

The site credentials you provided Waqar no longer work, and I need to see how your forms are set up so that I can try and match that on my local test site to understand why this isn't working.

Can I get updated credentials from you? I've set up a private reply.

#1321051

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi David

I'm looking at your site and I have some ideas about what the problem may be, but I need to test it and so I'm creating a test site now that reproduces your workflow with the auto-login.

I'll update you in a little while.

#1321097

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi David

I can't replicate the problem you describe despite repeated efforts with different combinations of settings etc.

I haven't tried it on your own site because it's a live site.

Do you have a staging site for testing?

Or can I try it with creating a dummy user on your live site?

A staging site would be better, as if there is no helpful info available in the browser dev tools looking at the network request then the next step would be to try a slimmed-down version of your site with all non-Toolset plugins disabled to see if something is conflicting in this process.

#1321731

I cannot send a private message so I edited the last private message I sent for the staging site details:

https://toolset.com/forums/topic/image-upload-error-on-post-form/#post-1319813

The install is bare bones, just the Divi theme and its child theme and the Toolset plugins I use on the live site. I have imported all Types, Views, Forms and Access from the live site as well. I also put in the following codes on my functions.php file: autologin for new CRED user, limit image upload file size and redirect to homepage after log out.

I have tried the process again and it's still giving me "An error occurred in the upload. Please try again later."

#1321885

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi David

Thanks for creating the test site. I was able to try a number of things but was still unable to get it to work.

There appeared to be something fundamentally wrong about auto-logging in the new user, because never mind the question of uploading images in a Toolset Form, if you clicked the logout link before trying anything else you were shown a 403 error.

Suspecting the issue may be specific to your server configuration I created a copy of your site and installed it locally.

There it worked fine, no problems uploading images for the auto-logged in user.

I can't think of what server settings would prevent the auto-login from working, I'm afraid, it may be something you need to discuss with your host.