0

I have the problem of sending parameters in form using POST method. I have texts and radios input within the form. The problem is only the radio type inputs are sent using that post, which means I lost the value in my text type inputs.

I have tried using $_REQUEST, and nothing changed.

FYI, I use materialize, and jQuery only

Here are my HTML code:

    <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>

And here is the PHP codes included above:

    $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;
halfer
  • 19,824
  • 17
  • 99
  • 186
Luckatme
  • 9
  • 6
  • 2
    Your input elements don't have a name attribute. Form elements are sent with name/value pairing. –  Aug 19 '16 at 01:31
  • Btw `$msg = $msg . 'xyz'` has a short form of `$msg .= 'xzy'`. This works for arithmetic and bit operating too – Manuel Mannhardt Aug 19 '16 at 01:34
  • And you dont need a WHERE-clause in your sql statements, just write `SELECT * FROM table` – Manuel Mannhardt Aug 19 '16 at 01:35
  • does anybody see any $_POST or $_GET? No. Btw, your question is way too unclear and a lot of code missing. You wanted help, then see the answers below then. You have no code to support all those tags too. – Funk Forty Niner Aug 19 '16 at 01:46
  • If that duplicate I marked as didn't solve this, then tell those guys who posted answers below, to change them or delete them. – Funk Forty Niner Aug 19 '16 at 01:48
  • Thanks, i though the id attribute will do the trick there. I really appreciate it :) @jeff – Luckatme Aug 19 '16 at 03:20
  • @ManuelMannhardt Thanks for your corrections regarding my code, guess i'm still a rookie here :) – Luckatme Aug 19 '16 at 03:23
  • @Fred-ii- the $_POST is on the create_soal.php which is in my form's action attribute. I dont post it because i think i dont need to post it, anyway thanks – Luckatme Aug 19 '16 at 03:25

2 Answers2

2

You have missed the name's tag of every text input field. So try this:

        $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;
Manikiran
  • 2,618
  • 1
  • 23
  • 39
0

you did not put a name to your input judul (if it is the input="text"). If there is no name, you cannot access to the data by $_POST