我是php和表单开发的新手,这就是我想要实现的目标:
首先,我有一个简单的表单只输入两个文本值:
Form1
<br>
<form action="gather.php" method="post">
Catalog:
<input type="text" name="folderName" maxlength="50">
<br>
File Name:
<input type="text" name="fileName" maxlength="50">
<br>
<input type="submit" name="formSubmit" value="Submit">
</form>
现在我有了第二个名为gather.php的文件,在那里我得到了两行,并使用它们来计算目录中的文件等。
<?php
if(isset($_POST['formSubmit'])){
$folderName = $_POST['folderName'];
$fileName = $_POST['fileName'];
$numberOfImages = count(glob($folderName . "/*.jpg"));
for($i = 1; $i <= $numberOfImages; $i++){
echo "<br><input type=\"text\" name=\"imie" . $i . "\"><br/>\n";
echo "<img src=\"" . $folderName . "/0" . $i . ".jpg\" height=\"50px\" width=\"50px\"><br><br>\n";
}
echo "\n<br>" . $folderName . "<br>" . $fileName . "\n";
}
?>
<br>
Final form
<br>
<form action="build.php" method="post">
<input type="submit" name="finalSubmit" value="Submit">
</form>
这应该让我看看build.php文件,它看起来更像这样:
<?php
if(isset($_POST['finalSubmit'])){
//loop and other stuff
$temp = $_POST['imie1'];
echo $temp;
}
?>
所以问题是,在这个最终文件中,我想获取放在gather.php文件中的文本字段中的所有数据。但是我在build.php上得到了未定义的索引错误,说$ _POST ['imie1']中没有任何内容。你能告诉我为什么吗? tehre是从第二个文件到第三个文件获取此数据的方法吗?
编辑:thx的答案,因为我只接受1和多个是相同的我选择最少代表的用户只是为了支持她:)
答案 0 :(得分:2)
您需要在表单标记内添加输入,否则不会发送。
<br>
Final form
<br>
<form action="build.php" method="post">
<?php
if(isset($_POST['formSubmit'])){
$folderName = $_POST['folderName'];
$fileName = $_POST['fileName'];
$numberOfImages = count(glob($folderName . "/*.jpg"));
for($i = 1; $i <= $numberOfImages; $i++){
echo "<br><input type=\"text\" name=\"imie" . $i . "\"><br/>\n";
echo "<img src=\"" . $folderName . "/0" . $i . ".jpg\" height=\"50px\" width=\"50px\"><br><br>\n";
}
echo "\n<br>" . $folderName . "<br>" . $fileName . "\n";
}
?>
<input type="submit" name="finalSubmit" value="Submit">
</form>
答案 1 :(得分:1)
用
替换你的gather.php<br>
Final form
<br>
<form action="build.php" method="post">
<?php
if(isset($_POST['formSubmit'])){
$folderName = $_POST['folderName'];
$fileName = $_POST['fileName'];
$numberOfImages = count(glob($folderName . "/*.jpg"));
for($i = 1; $i <= $numberOfImages; $i++){
echo "<br><input type=\"text\" name=\"imie" . $i . "\"><br/>\n";
echo "<img src=\"" . $folderName . "/0" . $i . ".jpg\" height=\"50px\" width=\"50px\"><br><br>\n";
}
echo "\n<br>" . $folderName . "<br>" . $fileName . "\n";
}
?>
<input type="submit" name="finalSubmit" value="Submit">
</form>
你回应了表单外的输入框,现在它可以正常工作
答案 2 :(得分:1)
我认为第二个表单上的<form>
需要位于文件的顶部 - 它只会在标记内部提交元素,因此您生成HTML然后打开表单,它就是没有提交。
<br>
Final form
<br>
<form action="build.php" method="post">
<?php
if(isset($_POST['formSubmit'])){
$folderName = $_POST['folderName'];
$fileName = $_POST['fileName'];
$numberOfImages = count(glob($folderName . "/*.jpg"));
for($i = 1; $i <= $numberOfImages; $i++){
echo "<br><input type=\"text\" name=\"imie" . $i . "\"><br/>\n";
echo "<img src=\"" . $folderName . "/0" . $i . ".jpg\" height=\"50px\" width=\"50px\"><br><br>\n";
}
echo "\n<br>" . $folderName . "<br>" . $fileName . "\n";
}
?>
<input type="submit" name="finalSubmit" value="Submit">
</form>