Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
html和php表单字段和提交_Php_Html_Forms_Submit_Field - Fatal编程技术网

html和php表单字段和提交

html和php表单字段和提交,php,html,forms,submit,field,Php,Html,Forms,Submit,Field,我在同一页上有一个简短的html表单和一些php代码,这样当表单提交时,条目就会出现在同一页上。此代码可以将输入的信息从表单发布到页面,但我有两个问题: 由于某种原因,文本框只允许我输入1个字符,现在它不允许我输入任何字符 每次我刷新页面以再次尝试表单时,信息都会不断追加。我只希望/需要它在提交后显示一次 <form method="post" action=""> <label>Select Out of Office Message <select nam

我在同一页上有一个简短的html表单和一些php代码,这样当表单提交时,条目就会出现在同一页上。此代码可以将输入的信息从表单发布到页面,但我有两个问题:

  • 由于某种原因,文本框只允许我输入1个字符,现在它不允许我输入任何字符

  • 每次我刷新页面以再次尝试表单时,信息都会不断追加。我只希望/需要它在提交后显示一次

    <form method="post" action="">
     <label>Select Out of Office Message
    
     <select name = "selectoutofofficemessage">
      <option value = "N/A">N/A</option>
      <option value = "Vacation">Vacation</option>
      <option value = "Conference">Conference</option>
      <option value = "Meeting">Meeting</option>
      <option value = "Other">Other</option>
     </select>
    
     <label>Custom Out of Office Message
     <input type="text" name="customoutofofficemessage" size="30" maxlength="255"/>
     </label>
    
     <p>
       <input type="submit" name="submit" value="Submit" />
     </p>
    </form>
    
    <?php
     $selectoutofofficemessage = $_POST["selectoutofofficemessage"];
     $customoutofofficemessage = $_POST["customoutofofficemessage"];
     $posts = file_get_contents("posts.txt");
     $posts = "$selectoutofofficemessage - $customoutofofficemessage\n" . $posts;
     file_put_contents("posts.txt", $posts);
     echo $posts;
    ?>
    
    
    选择外出信息
    不适用
    假期
    会议
    会合
    其他
    自定义外出消息
    
    


  • 1.第一个标签不正确,无法关闭。修复它:

    <label>Select Out of Office Message
       <select>
           ...
       </select>
    </label>
    
    选择外出信息
    ...
    
    2.更改您的PHP代码:

    <?php
    
    $posts = file_exists("posts.txt") ? file_get_contents("posts.txt") : "";
    
    if(!empty($_POST))
    {
        $selectoutofofficemessage = $_POST["selectoutofofficemessage"];
        $customoutofofficemessage = $_POST["customoutofofficemessage"];
        $posts = "$selectoutofofficemessage - $customoutofofficemessage\n" . $posts;
        file_put_contents("posts.txt", $posts);
    }
    
    echo $posts;
    

    对Post值进行验证

    if(isset(selectoutofofficemessage))
    
    {
    execute the html code;
    
    }

    否则 {

    php代码

    }然后,该值将不会重复一次又一次,也不会附加它,只需显示它即可。…

    
    
    <form method="post" action="">
    
    <label>Select Out of Office Message</label>
    <select name = "selectoutofofficemessage">
    
     <option selected="selected" value="">Select a Message</option>
    
     <option value ="N/A">N/A</option>
    
     <option value = "Vacation">Vacation</option>
    
     <option value = "Conference">Conference</option>
    
     <option value = "Meeting">Meeting</option>
    
     <option value = "Other">Other</option>
    
    </select>
    
    <label>Custom Out of Office Message</label>
    
    <input type="text" name="customoutofofficemessage" size="30" maxlength="255"/>
    
    
    
    <p>
    
    <input type="submit" name="submit" value="Submit" />
    
    </p>
    
    </form>
    
    
    <?php
    
    $posts = file_exists("posts.txt") ? file_get_contents("posts.txt") : "";
    
    if(!empty($_POST))
    {   
    $selectoutofofficemessage = $_POST["selectoutofofficemessage"];
    $customoutofofficemessage = $_POST["customoutofofficemessage"];
    $posts = "$selectoutofofficemessage - $customoutofofficemessage AT  <small><em>". date('h:m A - M-d-Y') ."</em></small>  <br>" . $posts;
    file_put_contents("posts.txt", $posts);
    }
    
    echo $posts;
    
    ?>
    
    <?php
    if (!empty($_POST)){
    ?>
    <script type="text/javascript">
        window.location = window.location.href;
    </script>
    <?php } ?>
    
    选择外出信息 选择一条消息 不适用 假期 会议 会合 其他 自定义外出消息

    window.location=window.location.href;
    注意你的(结尾)标签。缺少的标签-或标签内的输入标签。。。无法工作…@Petra标签内的输入标签完全有效,前提是标签标签已正确关闭。谢谢!真不敢相信我居然没看到那样的标签。。。提交表单后,它会清除(除选择框外,它会重置为第一个选项;“N/A”),如果我刷新,它仍会再次发布第一个选项。我尝试添加一条选择消息,但刷新后它仍然会重新显示“N/a”。看看这篇文章:嗯,也许我的代码顺序错了,或者我缺少标记?您发送给我的代码显示在网页上,它仍在附加表单信息。。。如果(isset(selectoutofofficemessage)){MY HTML FORM}或者{}您能在这方面进一步帮助我吗?我很快就要完成这项工作了。