Skip to content
Advertisement

Matching input text and input file to each other in PHP

I have a dynamic form that allows someone to add a row that has 2 input types. The first one can be an image or text field and the second one is always a text field. I need the first field to be tied with the second field in post. So I can add to a database field1A and field2A in the same row. The issue is that a file upload is in its own array so I can’t just loop through my text array and know that the image is tied to that text field.

JavaScript

If I loop through my field1[] array and get the index it will be different than my $_Files and I don’t know where in the array my files are.

JavaScript

Advertisement

Answer

Your best bet, like @fubar said would be to set the keys while you are rendering the html :

JavaScript

Then you could loop in PHP like this :

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement