Skip Navigation

[Escalated to 2nd Tier] CRED Image Fields

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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 9 replies, has 2 voices.

Last updated by Shane 2 years ago.

Assisted by: Shane.

Author
Posts
#2455349

If a user simply removes an image URL from an image field in a CRED edit form by clicking on the red cross, when the form is submitted I had expected the field would be updated to empty but the actual field is being removed from the post in the database.

Is this expected behaviour??

#2455595

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Julie,

Thank you for getting in touch.

Yes this is the expected behaviour as the record being removed is equivalent to an empty field. Meaning if you check the post on the backend you will see that the field is empty, this means there isn't any record in the database for that field for that specific post.

Please let me know if this helps.

Thanks,
Shane

#2456113

I can understand this being the behaviour for a repeating image field but for single image fields, this doesn't make sense.

If a user creates a post without uploading an image, the field is added to the database as an empty field. It is illogical to delete the entire meta entry if having uploaded an image to the field at some point, the user then later removes that image without replacing it with another.

Single Line fields, for example, remain in the database even if they've been updated to empty; why should image fields be any different??

I need to execute code in CRED hooks according to the field content on submission of the edit form. So if the image has been removed & not replaced, A happens, if a new image has been uploaded, B happens. It doesn't matter though how I check for the existence of or content of the image field (using empty, ! or ''), the conditions are ignored and both bits of code are executed triggering errors for the code that shouldn't run.

I can't even use

$variable = $_POST['wpcf-custom-field-name']

in the before save hook to capture the "old" field content. I'm able to do this is in scenarios that use other field types but not images. It's nonsense and inconsistent.

It seems the only way round this is to present the user with one form for removing without replacing and another for replacing or adding but that's just messy.

#2456477

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Julie,

Thanks for the additional information. Are you uploading the images using the media library ?

Perhaps you can set a default value.

Single Line fields, for example, remain in the database even if they've been updated to empty; why should image fields be any different??

Can you let me know the exact use case scenario so that I can try to replicate? Perhaps you can setup an example for me on our sandbox site so that I can go through to see exactly what happens.

Please let me know.
Thanks,
Shane

#2457801

No, I'm not using the Media Library.

I don't understand what it is you want to replicate. You've already confirmed that deletion of the field from the database is the expected behaviour when an image field is updated to empty. I am saying this behaviour is illogical and I've given good reasons for my opinion.

I think this should be referred to the developers with a view to changing the current behaviour so that the field is not removed from the database when updated to empty.

#2458405

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Julie,

I see what you mean in your condition, you aren't able to capture the old state of the field so it is causing some amount of issues with your code.

My recommendation here is that you submit an improvement request and providing as much details as is possible so that our developers can review it.
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

In terms of fixing this right now there isn't much that I can do from my end but perhaps you can employ the use of some form of Javascript or try using our forms hook below.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data

Since this is an edit form you should be able to access the post id from the URL and then retrieve the value from the database before it's deleted.

Please let me know if this helps.
Thanks,
Shane

#2459535

Capturing the old state of a field before the changes are saved is NOT a new feature; this is something that can be done with any other type of CRED field, just not image fields, using the before save hook (as I stated I'm using in my opening thread) and it shouldn't require the use of Javascript.

The whole problem is due to the image field being removed from the database. No other empty fields are removed from the database when a form is submitted and actually an empty image field is added to the database when a create CRED form is submitted so it's not unreasonable to expect empty fields to stay there. It's the behaviour of the edit form that's wrong.

All code is based on logic and consistency. There is NO logic or consistency here and it needs referring to the developers for change.

#2461009

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Julie,

Thanks for the clarity.

What I can do is to escalate this thread for further queries but as to when we will get a response to this one I cannot say.

If this is something that is to be fixed then it won't be on the priority list so you may need to find a workaround to this issue in the interim.

Thanks,
Shane

#2461307

Please mark as escalated

#2461575

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Julie,

I've escalated the thread to our 2nd tier team.

Also looking at your code again have you tried using the isset() function ?

For example


if(isset($_POST['wpcf-custom-field-name']))

This function checks if the field actually exist. This should work in the case where the field is filled out.
For the field not being fill out or the value removed you can do this.

if(!isset($_POST['wpcf-custom-field-name']))

Please let me know if this helps.

Thanks,
Shane