doforumda Posted November 19, 2009 Share Posted November 19, 2009 hi i create three php files. when i input number in first.php and pres go then it goes to second.php and displays there and work properly. But when in second .php when i input fields and press submit then it does not pass this first.php value throgh hidden type. my code is below. what am i doing wrong this code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form method="post" action="fileUploadForm.php"> <input name="numfields" type="text" size="3" maxlength="3" /> <input type="submit" name="fields" value="GO" /> </form> </body> </html> second page <?php $numfields = $_POST['numfields']; echo $numfields; if(is_numeric($numfields)) { for($i = 1; $i <= $numfields; $i++) { ?> <form enctype="multipart/form-data" method="post" action="uploadtutorial.php"> <label>Description:</label> <input type="text" name="desc<?php echo $i; ?>" /><br /> <label class="upload">Choose File:</label> <input type="file" name="uploadedfile<?php echo $i; ?>" id="file" /><br /> <?php } } else die("The input must be a number."); ?> <input name="numfields" type="hidden" value="<? echo $numfields;?>" /> <input type="submit" name="submit" value="Submit" /> </form> third page <?php $numfields = $_POST['numfields']; echo $numfields; for($i = 1; $i <= $numfields; $i++) { $description = $_POST['desc'. $i]; $filename = $_FILES['uploadedfile'. $i]['name']; echo $description."<br>"; echo $filename; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/182129-need-help-in-sending-hidden-field/ Share on other sites More sharing options...
cags Posted November 19, 2009 Share Posted November 19, 2009 Just a guess, but your script looks like it would actually create invalid HTML, which could potentially cause problems. If for example the number entered was 2, the resulting HTML would be... <form enctype="multipart/form-data" method="post" action="uploadtutorial.php"> <label>Description:</label> <input type="text" name="desc1" /><br /> <label class="upload">Choose File:</label> <input type="file" name="uploadedfile1" id="file" /><br /> <form enctype="multipart/form-data" method="post" action="uploadtutorial.php"> <label>Description:</label> <input type="text" name="desc2" /><br /> <label class="upload">Choose File:</label> <input type="file" name="uploadedfile2" id="file" /><br /> <input name="numfields" type="hidden" value="<? echo $numfields;?>" /> <input type="submit" name="submit" value="Submit" /> </form> You have two opening <form> tags and only one closing. No guarantee that's the problem, but it's certainly not a good idea. Move the form declaration line... <form enctype="multipart/form-data" method="post" action="uploadtutorial.php"> ... to before the loop. Quote Link to comment https://forums.phpfreaks.com/topic/182129-need-help-in-sending-hidden-field/#findComment-960921 Share on other sites More sharing options...
megaresp Posted November 19, 2009 Share Posted November 19, 2009 Cags is right. You're creating multiple forms, but only adding the hidden field to the last of them. It's all to do with your for loop. You need to move the final 2 fields and the closing form tag inside the for loop. That way, you're creating properly constructed forms with an opening and closing form tag. And your hidden fields will be inside each of the forms. Quote Link to comment https://forums.phpfreaks.com/topic/182129-need-help-in-sending-hidden-field/#findComment-961040 Share on other sites More sharing options...
cags Posted November 19, 2009 Share Posted November 19, 2009 If you do that you will end up with multiple forms, I assumed the OP only wanted one but with multiple inputs, hence the reason I suggested siimply moving the opening of the tag outside the loop. Quote Link to comment https://forums.phpfreaks.com/topic/182129-need-help-in-sending-hidden-field/#findComment-961042 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.