[英]PHP dynamic form input into a new html page form on submit
I am having some difficulty with inserting dynamic input fields into a new form html page. 我在将动态输入字段插入新的html页面时遇到了一些困难。 Essentially, I would like to get these dynamically created inputs into a new form field when the submit button is clicked on the previous page where the table dimensions are specified. 本质上,当您在指定表维度的上一页中单击“提交”按钮时,我想将这些动态创建的输入添加到新的表单字段中。 Currently, when I view the page source, the input fields are outside of the html body. 当前,当我查看页面源代码时,输入字段在html主体之外。 I would prefer not to have to use JavaScript just the keep things simple 我宁愿不必只是为了使事情简单而使用JavaScript
//page where dimensions are specified eg dimensions.html. //指定尺寸的页面,例如Dimensions.html。 clicking submit should bring you to a new page and display specified inputfields inside the html form. 单击提交将带您进入新页面,并在html表单内显示指定的输入字段。
<form action="script.php" method="post">
<label for="rows">Number of Rows (Min 1, Max 10)</label>
<input type="number" class="form-control" min="1" max="10" value="" name="rows" required>
<label for="columns">Number of Columns (Min 3, Max 10)</label>
<input type="number" class="form-control" min="3" max="10" value="" name="columns" required>
<input type="submit" name="submit2" value="Submit"/>
<input type="hidden" name="method" value="post" />
</form>
// loop for creating input fields from previous form input specifying table dimensions from seperate .php file
$row = (isset($_POST['rows']) ? $_POST['rows'] : null);
$col = (isset($_POST['columns']) ? $_POST['columns'] : null);
$x = $row * $col;
for ($i = 1; $i <= $x; $i++) {
echo "$i<input type='text' name='content[]' required>", "<br>";
}
// new html page form page eg content.html //新的html页面表单页面,例如content.html
<form action="script.php" method="post">
<input type="text" name="content[]">
// I would like to have the new fields input generated inside here //我想在这里生成新的字段输入
<input type="submit" name="submit3" value="Submit"/>
<input type="hidden" name="method" value="post"/>
</form>
You can do something like this, 你可以做这样的事情,
page1.php page1.php
<form action="page2.php" method="post">
<label for="rows">Number of Rows (Min 1, Max 10)</label>
<input type="number" class="form-control" min="1" max="10" value="" name="rows" required>
<label for="columns">Number of Columns (Min 3, Max 10)</label>
<input type="number" class="form-control" min="3" max="10" value="" name="columns" required>
<input type="submit" name="submit2" value="Submit"/>
<input type="hidden" name="method" value="post" />
</form>
page2.php page2.php
<?php
if(isset($_POST['submit2'])){
$row = $_POST['rows'];
$col = $_POST['columns'];
$x = $row * $col;
}
?>
<form action="script.php" method="post">
<input type="text" name="content[]">
<?php
if(isset($x)){
for ($i = 1; $i <= $x; $i++) {
echo "<input type='text' name='content[]' required><br>";
}
}
?>
<input type="submit" name="submit3" value="Submit"/>
<input type="hidden" name="method" value="post"/>
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.