[Resolved] Featured image isn’t uploading at all when posting using a Toolset form
This thread is resolved. Here is a description of the problem and solution.
Problem: I have a Form that is used to create posts. There is a featured image field in the Form that doesn't seem to be working. No AJAX upload indication appears when I select an image, and the image is not uploaded to the Media Library when I submit the Form.
Solution: In this case, a malformed HTML structure in the Form contents was the cause of this problem. The credform shortcode was nested incorrectly, causing a broken Form structure. Re-nesting the credform shortcode correctly in its wrapping div structure solved the problem.
This support ticket is created 6 years 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.
Hi, can you answer a few questions for me?
- Does this behavior only happen for Guests or does it also happen for Admins, etc?
- Is the image uploaded to the Media Library but not linked to the post, or is it not uploaded at all?
Then please try these troubleshooting steps next:
- Temporarily activate the parent Astra theme, and deactivate all plugins except Types, Views, Forms.
- Place the Form on a page somewhere so that it is accessible on the front-end of the site
- Submit the Form again and see if the image was uploaded successfully. If so, reactivate your theme and other plugins one by one until the problem returns.
- If the image was not uploaded successfully, please add this code to your child theme's functions.php file:
add_filter("cred_file_upload_disable_progress_bar", "disable_progress_bar");
function disable_progress_bar($val) {
return true; //return true to disable
}
- Now test the Form again. This time, the image will not be uploaded with AJAX but will be submitted along with the rest of the Form contents.
Okay let's try a few more things.
- Remove or deactivate that code so AJAX is active once again for image uploads.
- Create one of these posts in wp-admin. Is the Featured Image section visible? If not, scroll up to the top right corner and click "Screen options" to activate it. If you cannot see the Featured Image option available in Screen Options, you must activate it in the post type. Go to Toolset > Post Types and edit this post type. In the "sections to display when editing..." panel, make sure Featured Image is checked. Try again.
- Open the browser console and try to upload the featured image again. Watch for any JavaScript errors. Copy + paste those here for me to review.
- If no JS errors are displayed, open the network tab in the browser console and inspect the admin-ajax.php request that corresponds to the featured image upload (see the attachment here for an example). If you aren't sure which it is, you can refresh the page and wait for everything to load, then clear the list before submitting the featured image again. Copy + paste the entire "Response" contents here for me to review.
Let's see if any backend errors are being generated during the upload process. If you're not familiar with server logs, I can show you how to temporarily activate them. 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 before it says 'stop editing here':
Save that file and upload it to your server. Now attempt to upload the featured image via AJAX once more. If any server-side errors are generated, this will create an error_log.txt file in your site's root directory. Please send me its contents. Once that is done, you can revert the changes you made to wp-config.php.
If no errors are generated, I'll have to log in and take a closer look.
[03-Feb-2019 22:41:14 UTC] PHP Notice: Elementor\Responsive is deprecated since version 2.1.0! Use Elementor\Core\Responsive\Responsive instead. in /home/rochfordparishco/public_html/wp-includes/functions.php on line 4051
[03-Feb-2019 22:41:32 UTC] PHP Notice: Elementor\Responsive is deprecated since version 2.1.0! Use Elementor\Core\Responsive\Responsive instead. in /home/rochfordparishco/public_html/wp-includes/functions.php on line 4051
[03-Feb-2019 22:41:35 UTC] PHP Notice: Elementor\Responsive is deprecated since version 2.1.0! Use Elementor\Core\Responsive\Responsive instead. in /home/rochfordparishco/public_html/wp-includes/functions.php on line 4051
[03-Feb-2019 22:42:18 UTC] PHP Notice: Elementor\Responsive is deprecated since version 2.1.0! Use Elementor\Core\Responsive\Responsive instead. in /home/rochfordparishco/public_html/wp-includes/functions.php on line 4051
Okay that indicates a warning for Elementor, but if the issue continues with Elementor inactive then there must be something else going on. I can log in and create a clone of your site with the Duplicator plugin to do some more in-depth investigation if you provide login credentials in the private reply fields here. Please let me know how I can find this Form on the front-end of the site.
Okay I see what is happening now. You have an invalid markup structure in the Form. Basically the div.panel-body is closed before the credform shortcode is closed, but it should be closed after the credform shortcode is closed. Here's the code:
<div class="panel-body">
[credform]
[cred_field field="form_messages" class="alert alert-warning"]
<div class="form-group">
<label>Date and Time</label>
[cred_field field="meeting-date-and-time" force_type="field" class="form-control" output="bootstrap"]
</div>
<div class="form-group">
<label>Meeting Title</label>
[cred_field field="post_title" class="form-control" output="bootstrap"]
</div>
<div class="form-group">
<label>Meeting Content</label>
[cred_field field="post_content" output="bootstrap"]
</div>
</div> <!-- this closes the panel-body div before the credform shortcode is closed, resulting in an invalid markup structure -->
This should be fixed in your markup so that the credform shortcode is nested correctly inside its wrapper divs.
I'm attaching a screenshot here showing how the browser actually renders the Featured Image field outside the Form tag because the nested HTML structure is malformed.
Top man. I can't believe that was the issue. I've now moved the [credform] and [/credform] tags to the beginning and end and it's all working perfectly.