/    Sign up×
Community /Pin to ProfileBookmark

Validating dynamically created fields

Hi, I have an image upload page that creates a dynamic number of file upload boxes depending on how many the user wants.

They are numbered in sequential order Image0,Image1,Image2 etc…

The user then selects files for each input box and clicks the Submit button.

On the next page i need to check each one of these file input boxes and validate them to see if they are images and of the correct size etc…

The validation is no problem, but i can’t figure out how to get the values of the input boxes. I keep track of how many were created thru a hidden input field. so i know how many files i need to validate but i cant figure out how to get the values of the file input fileds.

I tried a For loop to loop the number of times that there are fields and create a varible with the same names as the fields and try to validate them but ofcourse the variables are empty because they are new variables and not the ones i passed from the last form.

Here is my code.

[code=php]
//Image checking
For($Counter =0; $Counter < $txtNumImages; $Counter++){
//Create variable with the same name as the input fields
$Image = “$Image”.$Counter;
$TypeTest = “False”;
ereg_replace (” “, “_”, $Image_name);
If ((!empty($Image) AND $Image_type == “image/pjpeg” AND $Image_type == “image/jpeg”) OR $Image_type == “image/gif”)$TypeTest = “True”;
If (!$TypeTest) $Error .= “<img src=”../images/errorarrow.gif” border=0>Image must be in either .jpg or .gif format.<br>”;
// Check To Make Sure Image Is Of Right Dimensions //
$ImageSize = getimagesize(“$Image”);
$ImageWidth = $ImageSize[0];
$ImageHeight = $ImageSize[1];
If ($ImageWidth < 400 Or $ImageHeight < 160)$Error .= “<img src=”../images/errorarrow.gif” border=0>Image is not the correct size, it must be exactly 400×160 in size.<br>”;
If ($Error != “”){
User_Error_Message($Error);
}else{
$FullPath = “/home/httpd/html/allsites/specialeventimages/”;
Copy($Image,$FullPath.$Image_name);
If(!Copy) Error_Message(“<img src=”../images/errorarrow.gif” border=0>Unable to copy image.”);
unlink ($Image);
}
}

[/code]

All the validation code works great.. i just can’t figure out how to get the values of the dynamically created input fileds on the last page.

Any help is appreciated!

Thanks!

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NevermoreMay 15.2003 — How are you passing the variables across - if you are using post, you set the variables with

$variable=$HTTP_POST_VARS('field');
Copy linkTweet thisAlerts:
@AdamGundryMay 15.2003 — As these are file uploads, shouldn't you be using $_FILES or $HTTP_POST_FILES?

See this page:

http://www.php.net/manual/tw/features.file-upload.php

Adam
Copy linkTweet thisAlerts:
@NevermoreMay 15.2003 — Good point.
×

Success!

Help @Arc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...