2016-09-15 8 views
-3

このHTML形式を使用して、エンドユーザーから情報を収集し、PHPを使用してテキストファイルに保存しようとしています。私は、テキストファイルが存在しないと仮定し、ファイルが存在するかどうかをチェックして追加することによって、これを達成できるさまざまな方法を探しています。誰にも何か提案はありますか?html5形式のデータをPHPを使用してtxtファイルに保存する方法

HTMLフォーム:私は本当に追加のは、これはテキストファイルにユーザーのフォームの送信を記録して、あなたの問題を解決するためにあなたに多くの指導を与える期待してみましょうするために何より知らない

<form id="newuser" method="post" action="newUser.php"> 
<fieldset> 
    <label for="name">Name</label> 
     <input type="text" name="name" placeholder="Full Name"> 
    <label for="email">E-mail</label> 
     <input type="email" name="email" placeholder="[email protected]"> 
    <label for="birthday">Birthday</label>       
     <input type="date" name="birthday" min="1929-12-31"> 
    <label for="phone">Phone</label> 
     <input type="tel" name="phone" placeholder="ex. (555) 555-5555">   
    <label for="message">Question/Comment</label> 
     <textarea name="message"></textarea> 
    <label>Check this box if you agree to the website 
     <a href="terms.php">terms</a> 
     <input type="checkbox" name="agreetoterms" value="Agree"> </label> 
     <input type="submit" name="submit" id="submit" value="Join Now" /> 
    </fieldset> </form> 
+0

次のように行うことができ、 "チェック" 以外の?? – RamRaider

+0

ここで[質問]に関する質問をお読みください。あなたは試したことを示すべきです。私たちはあなたがコードを修正するのを手伝いますが、私たちはコード作成サービスではありません。 –

+0

@RamRaider "newser.php"でなぜこの変更を行っているのか詳しく説明できますか?私はコードの行が何をしているのかよく分かりません。入力が表示されないのはなぜですか?もしそうなら、それは "storeFormData.txt"を指していてはなりませんか? – Chris

答えて

0

。 `;:(、しますprint_r($ _POST、真)、FILE_APPEND '/temp/form.txt C')`ますfile_put_contents - あなたは、単に `newuser.php`で

<?php 
    /* newuser.php */ 
    if($_SERVER['REQUEST_METHOD']=='POST'){ 

     /* 
      A path to where you wish to store the file, preferably outside of the document root. 
      The example path below is within the document root because there is no way of 
      knowing your directory structure. 
     */ 
     $saveto=$_SERVER['DOCUMENT_ROOT'] . '/folder/file.txt'; 


     if(!empty($_POST)){ 
      /* 

       Add the POSTed form contents to your file. 
       ------------------------------------------ 

       > The return of `file_put_contents` is the number of bytes written to the designated file. 
       > `print_r($var, true)` makes the output suitable for writing to file. 
       > `FILE_APPEND` & `FILE_TEXT` are two of the possible options `file_put_contents` accepts and are suitable for your question 

      */ 
      $bytes = @file_put_contents($saveto, print_r($_POST, true), FILE_APPEND | FILE_TEXT); 


      /* Process the form data however you would normally */ 
     } 


    } 
?> 
関連する問題