从生成的输入中获取值

时间:2015-04-01 18:36:26

标签: php html forms post input

您好我有一个输入生成“文本输入和一个提交输入”,我的问题是什么我无法获得用户写入生成的输入的值...这是我的代码:

<form method="post" action="">
    <input type="text" name="generator"/>
    <input type="submit" name="generatingsubmit"/>
</form>
<?php
if(isset($_POST['generator'])){
    $generator = $_POST['generator'];
    echo "<form method='post' action=''>";
    for($i = 0; $i < $generator; $i++){
        echo "<input type='text' name='" . $i ."'/>";
    }
    echo "<input type='submit' name='submit'/>";
    echo "</form>";
}
    echo $_POST[$i];
?>

1 个答案:

答案 0 :(得分:2)

我使用代码

创建了index.php
    <form method="post" action="index.php?action=post">
    <input type="text" name="generator"/>
    <input type="submit" name="generatingsubmit"/>
    </form>
    <?php
    if (isset($_GET['action']) && $_GET['action']=='post') {
    if(isset($_POST['generator'])){
    $generator = $_POST['generator'];
    echo "<form method='post' action='index.php?action=get_value'>";
    for($i = 0; $i < $generator; $i++){
        echo "<input type='text' name='somename[]'/><br />";
    }
    echo "<input type='submit' name='submit' />";
    echo "</form>";
    }
    }
    if (isset($_GET['action']) && $_GET['action']=='get_value') {
    $somename=$_POST['somename'];
    foreach( $somename as $n ) {
      print $n;
    }

    }
    ?>

一切正常,生成输入然后接收输入值。所有在一个 index.php 文件