如何从我的网页获取数据用户输入数据

时间:2017-04-16 15:28:45

标签: javascript php html

我在我的网站上创建了一个表单,这将允许我获得有关Rubik的立方体算法的建议,但是如何知道用户的输入?为了更好地理解,我给出了以下代码:

<form method="POST">
        <label>Your name: </label><br>
        <input type="text" name="name" placeholder="Your Name" required><br><br>
        <label>Your E-mail: </label><br>
        <input type="email" name="email" placeholder="email@domain.com" required><br><br>
        <label>Select puzzle: </label><br>
        <input type="radio" name="2x2" value="2x2">2x2<br>
        <input type="radio" name="3x3" value="3x3">3x3<br><br>
        <label>Select set/subset: </label><br>
        <input list="set"><br><br>
        <datalist id="set">
            <option>Ortega OLL</option>
            <option>Ortega PBLL</option>
            <option>CLL</option>
            <option>EG-1</option>
            <option>EG-2</option>
            <option>F2L</option>
            <option>OLL</option>
            <option>PLL</option>
            <option>COLL</option>
            <option>WV</option>
        </datalist>
        <label>Your Alg: </label><br>
        <input type="text" name="alg"><br><br>
        <input type="submit" name="submit" class="w3-black w3-button w3-hover-white w3-hover-text-blue w3-text-white">
      </form>

2 个答案:

答案 0 :(得分:0)

请在您的表单标记中添加操作属性,此处提交的是示例

<form action="getvalue.php" method="post">

</form>

注意:每个表单元素都必须具有唯一的名称。

添加action属性后,创建getvalue.php文件并将以下代码添加到其中

<?php 
    print_r($_POST);

&GT?;  上面的代码将给出所有表单字段值

让我知道它是否有用...

答案 1 :(得分:0)

我不确定你想要做什么,但这里有一个提交给自己的表格的例子。这将允许您在提交表单后保持在同一页面上。您可以更改用户看到的内容以表明表单已成功完成/等。我已经测试了这段代码并且有效。

<main>
    <?php

    // When the form is submitted
    if (isset($_POST["submitButton"])){

        //Do something with the data from the form - you don't have to print it out. 
        //This is all done on the server. 
        //Connect to DATABASE, send an EMAIL, VALIDATE the form, etc.

        print("<pre>");
        print_r($_POST);  // for all GET variables
        print("</pre>")

        ?>
        <!-- This HTML will be visible to the user after the form has been submitted. -->
        <h1>The form has been submitted successfully!</h1>
        <?php



    }else{  //If the form has not been submitted
        ?>

        <form method = "post" >
            First name:<br>
            <input type="text" name="firstname" value="Mickey">
            <br>
            Last name:<br>
            <input type="text" name="lastname" value="Mouse">
            <br><br>
            <input type="submit" id = "submitButton" name = "submitButton" value="Submit">
        </form>


        <?php
    } //End else
    ?>

</main>