Jump to content

need help in naming and posting input fields


doforumda

Recommended Posts

hi

 

i create form. what this does is when the user come to the page he has to enter the number of fields that how many input fields he needs. he type e.g, 5 then press go. so 5 input fields will be appear. then what i want is how can i name these inputs so when the user completes and press submit so that the values will be processed to php side and echo out these names. my code is below

 

<!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="dynamicFields.php">
<input name="numfields" type="text" size="3" maxlength="3" />
<input type="submit" name="fields" value="GO" />
</form>
<?php
if(isset($_POST['fields']))
{
$numfields = $_POST['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" /><br />
                <label class="upload">Choose File:</label>
                <input type="file" name="uploadedfile" id="file" /><br />
                
            
            <?php
	}
}
else
	die("The input must be a number.");
}
?>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>

 

the process these values code is here

 

<?php
if($_POST['submit'])
{
$description = $_POST['desc'];
$filename = $_FILES['uploadedfile']['name'];

echo $description."<br>";
echo $filename;
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.