Forum

Thread tagged as: Problem, PayPal

Problem with hidden form field affecting image upload

I have a hidden form field in my shop product page (add to basket) to store in the shopping cart session (I don't use mincart) the product image, rather than making a call to the db each time the product image needs to be displayed. However I have just found out that what I have put in is causing issues with trying to add or update the main product image and I am not sure how to resolve it.

In the product html page, I have the following for displaying the image (which also creates the image upload in the admin area):

<perch:if exists="productMainImage">
                <img itemprop="image" src="<perch:shop id="productMainImage" label="Main Image" type="image" width="383" height="563" crop="true" bucket="shop-images" />" alt="<perch:shop id="productTitle" />" class="main-image" />
            <perch:else />
                <img src="/assets/images/image-placeholder.jpg" alt="<perch:shop id="productTitle" /> Image Placeholder (no product image available)" class="main-image">
            </perch:if>

And then in the add to basket form I have something similar to add the image path to the session:

<perch:if exists="productMainImage">
                    <input type="hidden" name="item_image" value="<perch:shop id="productMainImage" type="hidden" />">
                <perch:else />
                    <input type="hidden" name="item_image" value="/assets/images/image-placeholder.jpg">
                </perch:if>

For some reason though (and I know it is this due to testing), this piece of code prevents the product's main image from being added or updated, in fact if a main image already existed (before I put this piece of code in) it is being removed from the product data in the database completely as soon as the product is saved again for any reason.

Emma Davis

Emma Davis 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Which template is this in?

product.html

Drew McLellan

Drew McLellan 2638 points
Perch Support

Does it occur before or after the main definition of productMainImage in the template? Remember Perch will take the first instance of each ID as the definition for the field when using a master template.

I did wonder if that was the case. The hidden field is before the main definition. I will have to think of a way around it then as I don't want the form containing everything on the page which is what I would have to do to get this working properly.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Why? Could you not change the order?

Umm, I just didn't want to contain the whole page within a form but I suppose it doesn't matter really and would be the easiest solution.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't think you should need to - just add a copy of the field higher up in your template.

That doesn't work with my layout so I have just contained it all within the form and the problem is resolved.