HTML + PHP。使用POST的表单不发送输入类型=文本

时间:2016-08-19 01:28:31

标签: javascript php jquery html forms

我有使用POST方法在表单中发送参数的问题。我在表单中输入了文本和无线电。问题是只使用该帖子发送无线电类型输入,这意味着我在文本类型输入中丢失了值。

我尝试过使用$ _REQUEST,但没有任何改变。

仅供参考,我使用materialize,仅使用jQuery

以下是我的HTML代码:

    <form id="testingform" name="testingform" method = "POST" action = "controller/create_soal.php">
            <?php include "controller/soal_editor.php";?>
            <div id="soal_baru"></div>
            <div class="row">
                <input class="waves-effect waves-light btn col s12" type="button" onClick="newSoal()" value="+ Tambah Soal"/>
            </div>
            <div class="row">
                <input type="submit" value="Publish >>>" class="waves-effect waves-light btn col s12"/>
            </div>
        </form>

以下是上面包含的PHP代码:

    $msg = $msg . '<div  class = "card-panel">
                    <div class = "row">
                        <div class="input-field col s12">
                            <input placeholder="Judul" id="judul" type="text" form="testingform" class="active validate" required/>
                            <label for="judul">Judul</label>
                        </div>
                    </div>
                    <div class = "row">
                        <div class="input-field col s12" style="color:#d5d5d5;">
                            Deadline:
                        </div>
                        <div class="input-field col s6">
                            <input placeholder="Deadline" id="deadline" type="datetime-local" required/>
                        </div>
                    </div>
                    <div class = "row">
                        <div class="input-field col s6">
                                <p>Ujian ini ditujukan untuk:</p>';
$sql = "SELECT * FROM jabatan WHERE 1;";
$retval = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) {
    $msg = $msg . '<p>
                        <input id="' . $row['id'] . 'jabatan" type="radio" name="jabatan" value="' . $row['id'] . '"/>
                        <label for="' . $row['id'] . 'jabatan">' . $row['label'] . '</label>
                    </p>';
}
$msg = $msg . '</div><div class="input-field col s6"><p>Ujian ini untuk menilai:</p>';
$sql1 = "SELECT * FROM dimensi WHERE 1;";
$retval1 = mysqli_query($conn, $sql1);
while ($row = mysqli_fetch_array($retval1, MYSQLI_ASSOC)) {
    $msg = $msg . '<p>
                        <input id="' . $row['id'] . 'dimensi" type="radio" name="dimensi" value="' . $row['id'] . '"/>
                        <label for="' . $row['id'] . 'dimensi">' . $row['labeldimensi'] . '</label>
                    </p>';
}
$msg = $msg . '</div></div></div>';
echo $msg;

2 个答案:

答案 0 :(得分:2)

您错过了每个文字输入字段的名称标记。所以试试这个:

        $msg = $msg . '<div  class = "card-panel">
            <div class = "row">
            <div class="input-field col s12">
                <input placeholder="Judul" id="judul" name="judul" type="text" form="testingform" class="active validate" required/>
                <label for="judul">Judul</label>
            </div>
            </div>
            <div class = "row">
            <div class="input-field col s12" style="color:#d5d5d5;">
                Deadline:
            </div>
            <div class="input-field col s6">
                <input placeholder="Deadline" id="deadline" name="deadline" type="datetime-local" required/>
            </div>
            </div>
            <div class = "row">
            <div class="input-field col s6">
                <p>Ujian ini ditujukan untuk:</p>';
$sql = "SELECT * FROM jabatan WHERE 1;";
$retval = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) {
    $msg = $msg . '<p>
            <input id="' . $row['id'] . 'jabatan" type="radio" name="jabatan" value="' . $row['id'] . '"/>
            <label for="' . $row['id'] . 'jabatan">' . $row['label'] . '</label>
            </p>';
}
$msg = $msg . '</div><div class="input-field col s6"><p>Ujian ini untuk menilai:</p>';
$sql1 = "SELECT * FROM dimensi WHERE 1;";
$retval1 = mysqli_query($conn, $sql1);
while ($row = mysqli_fetch_array($retval1, MYSQLI_ASSOC)) {
    $msg = $msg . '<p>
            <input id="' . $row['id'] . 'dimensi" type="radio" name="dimensi" value="' . $row['id'] . '"/>
            <label for="' . $row['id'] . 'dimensi">' . $row['labeldimensi'] . '</label>
            </p>';
}
$msg .= '</div></div></div>';
echo $msg;

答案 1 :(得分:0)

你没有为你的输入判断命名(如果是输入=“文本”)。如果没有名称,则无法通过$ _POST

访问数据