PHP表单 - 处理Textfield不起作用

时间:2014-02-10 15:24:57

标签: php html

我目前正在尝试进行表单验证,检查某些输入/文本字段是否为空。我希望保存文本字段中的文本并再次输入文本字段中的下一个php文件。它适用于所有输入,但不适用于文本字段。网站加载但文本字段只是空的。

让你感到期待!

HTML PART:

<form id="formularheader" name="form" method="post" action="php/contact.php">
                        <fieldset id="personenInfo">


                            <p><label for="message" >Nachricht *</label></p>
                            <p><textarea name="nachricht" id="message" cols="40" rows="10" required=""></textarea></p>

                            <div class="terms">
                                <input type="checkbox" name="terms">
                            </div>

                            <p style="font-size: 80%; color: #292929; font-style: italic;">* notwendige Angaben</p>
                        </fieldset>

                        <input type="submit" id="submitButton" value="Abschicken">
                    </form>

PHP PART:

<?php 

$message = $_POST['message'];

?>

<form id="formularheader" name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
                        <fieldset id="personenInfo">

                            <p><label for="message">Nachricht *</label></p>
                            <p><textarea name="nachricht" id="message" value="<? echo $message; ?>" cols="50" rows="10" required=""></textarea></p>

                            <div class="terms">
                                <input type="checkbox" name="terms">
                            </div>

                            <p style="font-size: 80%; color: #292929; font-style: italic;">* notwendige Angaben</p>
                        </fieldset>

                        <input type="submit" id="submitButton" value="Abschicken">
                    </form>

3 个答案:

答案 0 :(得分:0)

应为$_POST["nachricht"](在POST时考虑名称属性)

答案 1 :(得分:0)

您需要使用字段名称而不是ID,例如$ _POST ['NAME']而你有$ _POST ['id']

答案 2 :(得分:0)

可以使用多个级别的验证:

  1. 使用HTML5工具:添加每个输入所需的内容以拒绝用户发送空输入
  2. 使用if(isset())