How to add a server side validate step on a repeat element

I am having some issues adding a server side validate step on an element.

Its an input inside a repeat, for uploading files, i need to validate that the file name does not already exist on the server.

Steps
Database Connection
Repeat
Validate Data

Here are the settings you can not see
Expression

{{'/african-and-indian-ocean-holiday-images/header-slideshows/'+slideshow_image_name.lowercase()}}

Linked Field

record_for_multi_insert[{{$index}}][slideshow_image_name]

What this is doing is kind of working but not exactly, if i upload one image that i know to be a duplicate name, it processes than adds a message under the one field that is already exists in the database and it does not upload or save the name into the database, so perfect.

If i upload 2 images and both are duplicate, it adds the error to only the first input field about already existing in the database and neither upload or get added to the database, so I could kind of live with that, but would be better if both fields told us they were already in the database.

The issue really starts if I upload input 1 as a unique image and input 2 as a duplicate image, the error comes up on input 2 only as it should, however image 1 is uploaded to the server and the value is saved to the database, which I would rather the entire form fail not just one part of it.

I assume I have just entered in incorrect values into the expression or Linked Field possibly, but if someone could try advise please.

So after a chat with Teo I kind of settled on letting Wappler check for me and then rename the image with a -01.jpg appended to the end, although, it wasnt really what i wanted, so another 3 hours later i figured it out.

It works perfectly and checks each image against the database, and all it took was adding multiple rules inside the validator, like this

And it works, hahahaha, Wappler is the bestest still.

2 Likes

I think I follow what you mean. Do you need to validate each entry inside the repeat?

If so then just do a query on the filename the do the update inside a condition

i.e.
repeat for imagelist
query image name
If imagename found
then action
else other action

What i needed to do was.

The person uses a form select and chooses how many single image upload file fields they need.

The reason for not just using a multi upload form is because I need the client to rename all their images, unless they have actually followed my SEO naming guidelines before uploading, but generally they havent, and i would have image1.JPG, image1.jpg, image1.jpeg, wa0000000567.jpg etc. which would really give me no SEO advantage at all.

So each single file upload field has a name field that goes with it.

I basically needed a multi insert form, but before database insert or image upload I needed a validator step.
The problem I faced was inserting the validator step inside the repeat only checks each image per repeat, so if image field 1 and 2 were perfect and image field 3 was wrong, it was uploading and storing the first 2 in the database before giving an error for the third image.

I then tried your way, but being fully serverside I could not seem to get the error to report on the correct file field so the user would know which image name was incorrect, it would just report the first one it found, then they would fix that, hit go again and it would then say another image 3 more down was also incorrect.

With the validator solution, it reports the entire list on the correct fields and stops the entire process running all at the same time, which was finally what i was hoping for.

Just brainstoming ideas here but could you not add a response stage to the server action to be triggered if the image is in error and return and error code and the image name as the response text? You could then pick up the text in the server connect Error dynamic event and trigger a flow? Would that help?

yeah, i think it would but i couldnt really work it out, i probably tried this out for 9 hours in total, and I think at some point I was doing round trips all over the place, shoving temporary names into arrays and variables etc. It really did get quite messy, it was only when i literally went back to the absolute basics, a file upload field, a text input field getting the file name from the upload initially and then editable.

A server action with just the basic database connection a validator and a repeat with the normal steps as would be added by the multi insert form generator, so the only real part i had to really fight with was the validator step, because without it being inside a repeat, figuring out the paths was a bit of a pain, but not too bad.

Because i had 20 files as the maximum allowed it was achievable at least.
the expressions look like this

{{'/african-and-indian-ocean-holiday-images/header-slideshows/'+$_POST.record_for_multi_insert[0].slideshow_image_name.lowercase()}}

and the file field targets like this

record_for_multi_insert[0][slideshow_image_name]

and in every step i needed to manualy increment the [0] from 0-19 to account for all 20 fields, so i think if anything, I could try get that into a repeat, and when that entire repeat has passed validation, then it runs the next repeat with all it’s steps. But I couldnt work it out.

Would be very interested if you wouldnt mind setting up a test case and seeing if you can find a way to simplify the process, or anyone else who wants to take a crack at it.

Watch Patrick come back with, remove all steps but one, add .#/20 and it all works or something crazy to make me feel really doff

1 Like